MaratonIME helps Pablito

本文介绍了一种利用智能算法快速判断两种生物是否拥有共同祖先的方法,通过计算两个个体ID之间的最大公约数,来确定它们是否共享相同的基因起源。此方法在生物遗传学研究中具有广泛的应用前景。

♬ Caloventor tiene miedo... ♬

Benedetto, Nathan

As is well known by any cultured person, rats are the smartest beings on earth. Followed directly by dolphins.

MaratonIME knows about the species hierarchy and uses this knowledge in it's regard. Usually, when they need some resource, they know it's always useful to have a smart rat available. Unfortunately, rats are not very fond of us, primates, and will only help us if they owe us some favour.

With that in mind, MaratonIME decided to help a little rat called Pablito. Pablito is studying rat's genealogy, to help with cloning and genetic mapping. luckily, the way rats identify themselves make the job much easier.

The rat society is, historically, matriarchal. At first, there were little families, each of which had it's own leading matriarch. At that time, it was decided that rats would organize themselves according to the following rules:

  • Each martiarch had an id number greater than one.
  • Each of these ids were chosen in a way such that they would have the least amount of divisors possible.
  • Each family member had the same id as the matriarch.
  • The id of any newborn rat would be the product of its parents id's.

For instance, the offspring of a rat with id 6 and another with id 7 is 42.

Pablito needs to know if two given rats have a common ancestor, but his only tool is the id number of each of the two rats, which is always a positive integer greater than 1 with no more than 16 digits. Can you help him?

Create a program that decides if a pair of rats have some common ancestor.

Input

The input begins with a positive integer t ≤ 10^5, the number of test cases.

After that, follows t lines, each with two integers ai e bi identifying two rats.

Every rat's id is a positive integer greater than 1 and with no more than 16 digits.

Output

For each test case, print "Sim" if the rats ai and bi share a common ancestor and "Nao" otherwise.

Example

Input

2
2 4
3 5

Output

Sim
Nao

前言:这道题一开始理解题意理解了很久。。。也没看懂。最后发现是个签到题,贼简单。于是意识到,看英文题的时候,一些样例和关键字才是需要最注重的地方,把握住这些,题目的真正意思就读懂了,没必要一直纠结于看不懂大篇的文章。

最后补题的时候也爆int了,因为把Every rat's id is a positive integer greater than 1 and with no more than 16 digits.理解成最大不超过16了,digit是数字和数位的意思,这里是不超过16数位的意思。其实,从常识来看的话,也不应该理解成16的,英语单词有多义,看错了意思,也应该抱着怀疑的心态去读题,和题意、常识有矛盾的话就要去猜测、深究。

题解:

题意概括:

从例子来理解题意较为简单。

例子:6*7=42,所以说 6 和 7 是 42 的祖先,如果来一个数12,那么它和42有公共祖先,因为有公约数6,如果来一个数28,那么它和42有公共祖先,因为有公约数7。测试数据,2 和 4 有公约数2,所以有共同祖先;3 和 5没有除了 1 的公约数,所以没有共同的祖先。其实这道题简而言之,求两个数之间是否有公约数 ,有便输出Sim ,没有便输出Nao。

AC代码:

#include <bits/stdc++.h> 

typedef long long ll;

using namespace std;

ll gcd(ll a, ll b)
{
	return b? gcd(b, a % b) : a;
}
 
int main()
{
	//freopen("input.txt", "r", stdin);
	//提交时注释,调试时取消注释!!! 
	
	long long n;
	
	cin >> n;
	
	long long u, v;
	
	while(n -- )
	{
		cin >> u >> v;
		long long num = gcd(u, v);
		
		if(num > 1) cout << "Sim" << endl;
		else cout << "Nao" << endl;
	}
		
	
		
	return 0;
}

如果想更简单些,直接上的话,用函数内置gcd即可。

#include <bits/stdc++.h> 

typedef long long ll;

using namespace std;
 
int main()
{
	//freopen("input.txt", "r", stdin);
	//提交时注释,调试时取消注释!!! 
	
	long long n;
	
	cin >> n;
	
	long long u, v;
	
	while(n -- )
	{
		cin >> u >> v;
		long long num = __gcd(u, v);
		
		if(num > 1) cout << "Sim" << endl;
		else cout << "Nao" << endl;
	}
		
	
		
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值