HDU 2040 亲和数
这题本来准备打表的,但是后来看数据600000 MY god 太大了 所以还是决定计算
代码
#include<stdio.h>
#include<stdlib.h>
int judge ( int a,int b )
{
long long i,j,sum1 = 0,sum2 = 0;
for ( i = 1 ; i <= a / 2;++i )
if ( a % i == 0 )
sum1 += i;
for ( j = 1; j <= b / 2; ++j )
if ( b % j == 0 )
sum2 += j;
if(sum1 == b && sum2 == a )
return 1;
else
return 0;
}
int main ( )
{
int a,b,N,t;
while ( scanf ( "%d",&N ) ==1 )
{
while ( N-- )
{
scanf ( "%d%d",&a,&b );
judge( a,b ) ? printf ( "YES\n" ):printf ( "NO\n" );
}
}
return 0;
}
本人还是新手 ,转载请注明来自Lvsi‘s home