2012 Multi-University Training Contest 3:Arcane Numbers 1

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.
 
SampleInput
3
5 5
2 3
1000 2000
 
SampleOutput
Case #1: YES
Case #2: NO
Case #3: YES
 
Author
Vance and Shackler

//题意:问一个A进制下的有限小数嫩否在B进制下也是有限小数。 
//一个小数x转换为A进制就是不断的除以A,可以记为x*A^(-p) 。 而这个有限小数要转化为 B进制下的小数,按进制转换规则就要不断乘以B,直到得到一个整数,最后将这个整数做B进制处理然后小数点向右移m位,m为乘以B的次数。  所以,A进制下的小数x*A(-p)一直乘以B后必须为整数,即x*(A^(-p))*(B^q)为整数,则要求B^q%A^p==0。其中p,q可以为任意值。 显然要求A的所有质因子都必须被B包含。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<algorithm>
#include<ctime>
using namespace std;
#define maxn 1000000
#define LL __int64

bool x[maxn+10];
int prime[maxn+10],num=0;
void Init()
{
	int i,tmp;
	memset(x,false,sizeof(x));
	x[0]=x[1]=true;
	for(i=2;i<=maxn;i++)
		if(!x[i])
		{
			prime[++num]=i;
			tmp=i*2;
			while(tmp<=maxn)
			{
				x[tmp]=true;
				tmp+=i;
			}
		}
}

int main()
{
	Init();
	int T,t=0,i;
	LL n,m;
	LL A[100];
	scanf("%d",&T);
	while(T--)
	{
		int cnta=0;
		scanf("%I64d%I64d",&n,&m);
		printf("Case #%d: ",++t);
		if(n==m)
		{
			puts("YES");
			continue;
		}
		for(i=1;i<=num&&(LL)prime[i]*prime[i]<=n;i++)
			if(n&&n%prime[i]==0)
			{
				A[++cnta]=prime[i];
				while(n&&n%prime[i]==0)
					n/=prime[i];
			}
		if(n>1)
			A[++cnta]=n;
		bool flag=true;
		for(i=1;i<=cnta;i++)
			if(m%A[i]!=0)
			{
				flag=false;
				break;
			}
		printf("%s\n",flag?"YES":"NO");
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值