您的位置:首页 > 其它

hdu 4320 Arcane Numbers 1

2012-08-01 14:35 351 查看

Arcane Numbers 1

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 871 Accepted Submission(s): 277


[align=left]Problem Description[/align]
Vance and Shackler like playing games. One day, they are playing a game called "arcane numbers". The game is pretty simple, Vance writes down a finite decimal under base A, and then Shackler translates it under base B. If Shackler can translate it into a finite decimal, he wins, else it will be Vance’s win. Now given A and B, please help Vance to determine whether he will win or not. Note that they are playing this game using a mystery language so that A and B may be up to 10^12.

[align=left]Input[/align]
The first line contains a single integer T, the number of test cases.
For each case, there’s a single line contains A and B.

[align=left]Output[/align]
For each case, output “NO” if Vance will win the game. Otherwise, print “YES”. See Sample Output for more details.

[align=left]Sample Input[/align]

3 5 5 2 3 1000 2000

[align=left]Sample Output[/align]

Case #1: YES Case #2: NO Case #3: YES

[align=left]Author[/align]
Vance and Shackler

[align=left]Source[/align]
2012 Multi-University Training Contest 3

[align=left]Recommend[/align]
zhoujiaqi2010

检查A中的质因子 是否都在 B中被包含。

#include <stdio.h>
#include <string.h>
#include <math.h>
#define maxn 1000009
int p[maxn],a[maxn];
int n,m;
int cnt;
void prime( )
{
int i,j;
cnt=0;
a[0]=a[1]=0;
for( i=2;i<=1000000;i++)
a[i]=1;
for( i=2;i<=1000;i++)
{
if(a[i])
for( j=2;j*i<=1000000;j++)
a[i*j]=0;
}
for( i=2;i<=1000000;i++)
if(a[i]) p[cnt++]=i;

}
int main( )
{
int tests,sign;
__int64 a,b;
int i;
int cases=0; prime( );
scanf("%d",&tests);

while(tests--)
{
sign=1;
scanf("%I64d%I64d",&a,&b);
int LIM=(int)sqrt(double(a));
for( i=0;p[i]<=LIM;i++)
{
if(a%p[i]==0)
{
if(b%p[i]!=0)
{
sign=0;
break;
}
while(a%p[i]==0)
a/=p[i];
}
}
if(a!=1&&(b%a!=0)) {sign=0;}
if(sign==0) printf("Case #%d: NO\n",++cases);
else printf("Case #%d: YES\n",++cases);
}
return 0;
}

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4320
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: