现在的位置: 首页 > 综合 > 正文

HDU – 4320 Arcane Numbers 1

2012年12月10日 ⁄ 综合 ⁄ 共 1037字 ⁄ 字号 评论关闭

开始的时候没看懂 a finite decimal,

我以为是有限小数的数, 其实也是...吧....好吧好像这没什么关系(因为整数部分各数值可以随意转换么.....虽然我当时抽了以为不可以.....)

但是我没意识到这是小数的数值转换, 十进制小数转二进制是乘二取整么(注意这里进位是十进制的).

然后看了两份题解

http://www.cnblogs.com/Lyush/archive/2012/08/01/2617780.html

http://blog.csdn.net/diannaok/article/details/7815545

然后还无聊去查了下因数跟约数的区别...http://zhidao.baidu.com/question/129997629.html , 差不多, 我的理解是因数不一定是整数.

但质因数总归是整数了, 而且质因数重复只算一个, 约数个数是每个质因数的指数加一累乘......恶补..

所以这题就是求: B中是否包含A中所有质因数

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<map>
using namespace std;
int Rint() { int x; scanf("%d", &x); return x; }
#define FOR(i, a, b) for(int i=(a); i<=(b); i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(x) for(int i=0; i<(x); i++)
typedef long long int64;
#define INF (1<<30)
#define bug(s) cout<<#s<<"="<<s

int64 n, m;

int64 gcd(int64 x, int64 y)
{
	return y==0? x: gcd(y, x%y);
}

int main()
{
	int t = Rint();
	for(int T=0; T<t; T++)
	{
		printf("Case #%d: ", T+1);
		scanf("%I64d%I64d", &n, &m);
		for(;;)
		{
			int64 g = gcd(n, m);
			if(g!=1)
			{
				n/=g;
			}
			else
			{
				if(n == 1)		// m包含n所有因数 
				{
					printf("YES\n");		
				}
				else
				{
					printf("NO\n");
				}
				break;
			}
		}
	}
}

抱歉!评论已关闭.