Uva 371 一直超时 求大佬解答
程序代码:
#include <stdio.h> #include <stdlib.h> int Count(int n, int m); int main() { long long i, j, temp; int p, max, sum, maxnumber; while(scanf("%I64d%I64d",&i,&j) == 2 && (i != 0 && j != 0)) { if(i > j) { temp = i; i = j; j = temp; } sum = 0; max = 0; for(p = i; p <= j; p++) { sum = Count(p, j); if(sum > max) { max = sum; maxnumber = p; } } printf("Between %I64d and %I64d, %d generates the longest sequence of %d values.\n", i, j, maxnumber, max); } return 0; } int Count(int n, int m) { int i; i = 0; while(n != 1) { if(n%2 == 0) n/=2; else n = n*3 + 1; i++; } return i; }
求大佬解决超时问题