题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1041
这里有个博客讲的很不错(http://blog.csdn.net/csyzcyj/article/details/10044629),不过不知道为什么算出了总是多了一倍,除以2就A了额无语死。。。
代码:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std ;
#define ll long long
ll r , ans = 0 ;
ll gcd( ll x , ll y ) {
if ( x < y ) swap( x , y ) ;
while ( y ) {
ll k = y ;
y = x % y ;
x = k ;
}
return x ;
}
void solve( ll d ) {
for ( ll a = 0 ; a ++ < ( ll )( sqrt( d ) ) ; ) {
ll b = ( ll )( sqrt( d - a * a ) ) ;
if ( b * b == d - a * a ) {
if ( gcd( b * b , a * a ) == 1 && b != a ) {
++ ans ;
}
}
}
}
int main( ) {
scanf( "%lld" , &r ) ;
for ( ll i = 0 ; i ++ < ( ll )( sqrt( 2 * r ) ) ; ) {
if ( ! ( ( 2 * r ) % i ) ) {
solve( i ) ;
if ( ( 2 * r ) / i != i ) solve( ( 2 * r ) / i ) ;
}
}
printf( "%lld\n" , ans * 2 + 2 ) ;
return 0 ;
}
网友评论