|
〇〇 发表于 2012-2-9 09:58 ![]()
改变q的上界,q最大不超过1/2周长
create or replace procedure Q3702(arg number default 1e6) is
per ...
其实p也有上界,不能超过1/3周长,否则就不是最短边了,c程序验证通过
但改到pl/sql却出错了
#include <stdio.h>
#include <math.h>
#define M 10000000
int gcd(int a,int b)
{
int temp;if(a<b)/*交换两个数,使大数放在a上*/{temp=a;a=b;b=temp;}
while(b!=0)/*利用辗除法,直到b为0为止*/{temp=a%b;a=b;b=temp;}
return a;
}
int main()
{
int a;
int c;
int s=M/3;
for(int a0=2;a0<sqrt(M/3);a0++)
{a=a0*a0;
for(int c0=a0+1;c0<=sqrt(M/2);c0++)
{
if (gcd(a0,c0)==1)
{
c=c0*c0;
if( a+a0*c0>c && /*a<a0*c0 && a0*c0<c &&*/ a+a0*c0+c<=M)
s+=M/(a+a0*c0+c);
}
if(a%500000==1)
printf("%d,%d\n",a,s);
}
}
printf("%d",s);
return 1;
}
SQL> exec q3702(1E6)
853262 |
|