杭电ACM2040题

这里写图片描述

这道题关键是求出每一个约数。

#include<stdio.h> 
int main() 
{
    int n;
    int x,y,t,sum,i;
    scanf("%d",&n);
    while(n--)
    {
        sum=0;
        scanf("%d%d",&x,&y);
        if(x>y)
        {
            t=x;
            x=y;
            y=t;
        }
        for(i=1;i<=y/2;i++)
            if(y%i==0)
                sum+=i;
        if(sum==x)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0; 
}

猜你喜欢

转载自blog.csdn.net/qq_43104182/article/details/82426853