2013年5月12日 星期日

UVA 106 C++


#include<iostream>
using namespace std;
int gcd(int,int);
int main()
{
int n;
while(cin>>n)
{
bool *stored=new bool[n+1];
int count=0,second_count=0;
int f,s,t;
for(int a=1;a<=1000;a++)
for(int b=1;b<=a;b++)
{
if(gcd(a,b)!=1)
continue;
if((a-b)%2==0)
continue;
t=a*a+b*b;
if(t>n)
break;
count++;
f=a*a-b*b,s=2*a*b;
for (int i=1; t*i<=n; i++ )
stored[i*f]=stored[i*s]=stored[i*t]=1;
}
for(int j=1;j<=n;j++)
if(stored[j]==1)
second_count++;
cout<<count<<" "<<n-second_count<<endl;
}
return 0;
}
int gcd(int m,int n)
{
int Remainder;
while(Remainder=m%n)
{
m=n;
n=Remainder;
}
return n;
}

1 則留言: