Arcane Numbers 1

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


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
 

AC代码:

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int t;
int p[1000005]; //开到一半就行了;
int prime[400005];
__int64 a,b;
int flage;

void nilt() //筛选素数;
{
   for(int i=2;i<1000005;i++)
   p[i]=1;
   for(int i=2;i<205;i++)
   {
      int j=2;
   while(i*j<1000005)
   {
      p[i*j]=0;
   j++;      
      }    
   }  
   int rec=0;
   for(int i=2;i<1000005;i++)
   {
      if(p[i])
   prime[rec++]=i; //存取素数;    
   }
}

int main()
{
   scanf("%d",&t);
   nilt();
   int cnt=1;
   while(t--)
   {
      flage=0;
   scanf("%I64d%I64d",&a,&b);
   int s=(int)sqrt((double)a);
   for(int i=0;prime[i]<=s;i++)
   {
      int x=prime[i];
   if(a%x==0)
   {
      if(b%x!=0)
   {
      flage=1;
      break;    
            }   
   while(a%x==0)
   a/=x; 
   }    
      }   
      if(a!=1&&b%a!=0)
      flage=1;
      printf("Case #%d: ",cnt++);
      printf(flage?"NO\n":"YES\n");
   }  
   //system("pause");
   return 0;
}

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4320