- 论坛徽章:
- 0
|
我还没编译成Release的。n == 2000,用时不到1毫秒。
浮点在判断相等的时候,肯定会有问题的。
#include <time.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
int a;
int n = 2000;
int cnt = 0;
int r [2000];
int i;
int AMax = n - 2;
int CxCMax = (n - 1) * (n - 1);
clock_t begin, end;
begin = clock();
for (a = 2; a <= AMax; a ++)
{
if (a * a + (a + 1) * (a + 1) <= CxCMax)
r[cnt ++] = a;
}
end = clock();
for (i = 0; i < cnt; i++)
printf("%d^2 + %d^2 = %d\n", r[i], r[i] + 1, r[i] * r[i]);
printf(" -> time %ld, total %d\n", end - begin, cnt);
return 0;
}
|
1387^2 + 1388^2 = 1923769
1388^2 + 1389^2 = 1926544
1389^2 + 1390^2 = 1929321
1390^2 + 1391^2 = 1932100
1391^2 + 1392^2 = 1934881
1392^2 + 1393^2 = 1937664
1393^2 + 1394^2 = 1940449
1394^2 + 1395^2 = 1943236
1395^2 + 1396^2 = 1946025
1396^2 + 1397^2 = 1948816
1397^2 + 1398^2 = 1951609
1398^2 + 1399^2 = 1954404
1399^2 + 1400^2 = 1957201
1400^2 + 1401^2 = 1960000
1401^2 + 1402^2 = 1962801
1402^2 + 1403^2 = 1965604
1403^2 + 1404^2 = 1968409
1404^2 + 1405^2 = 1971216
1405^2 + 1406^2 = 1974025
1406^2 + 1407^2 = 1976836
1407^2 + 1408^2 = 1979649
1408^2 + 1409^2 = 1982464
1409^2 + 1410^2 = 1985281
1410^2 + 1411^2 = 1988100
1411^2 + 1412^2 = 1990921
1412^2 + 1413^2 = 1993744
1413^2 + 1414^2 = 1996569
-> time 0, total 1412 |
|