hdu 4320

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
__int64 gcd(__int64 a,__int64 b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}
int main()
{
    __int64 total;
    scanf("%I64d",&total);
    __int64 k=1;
    while(total--)
    {
        __int64 a,b;
        scanf("%I64d %I64d",&a,&b);
        __int64 h=gcd(a,b);
        if(a==1)
        {
            printf("Case #%I64d: YES\n",k++);
            continue;
        }
        while(a!=1)
        {
            a/=h;
            h=gcd(a,b);
            if(a!=1&&h==1)
            {
                printf("Case #%I64d: NO\n",k++);
                break;
            }
        }
        if(a==1)
        {
            printf("Case #%I64d: YES\n",k++);
            continue;
        }
    }
    return 0;
}
posted @ 2012-08-17 17:34  willzhang  阅读(189)  评论(0编辑  收藏  举报