hdu 4320 Arcane Numbers 1

 

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


Problem Description
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.
 

 

Input
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.
 

 

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

 

Sample Input
3 5 5 2 3 1000 2000
 

 

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

 

Author
Vance and Shackler
 

 

Source
 

 

Recommend
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

posted @ 2012-08-01 14:35  jiai  Views(313)  Comments(0Edit  收藏  举报