概述
A - MaratonIME helps Pablito
https://cn.vjudge.net/problem/488485/origin
♬ 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 ≤ 105, 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
**题意:**两个数有公约数即为这两个数有相同的祖先,若两个数存在同一个祖先,则输出:Sim,否则输出:Nao
**提示:**不能用一般的for循环进行查找,数太大就会超时
AC代码:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n;
long long int a,b,k;
scanf("%d",&n);
while(n--)
{
long long int z=0;
scanf("%lld %lld",&a,&b);
if(a>b)
{
k=a;
a=b;
b=k;
}
if(b/a==0) printf("Simn");
else
{
while(b%a!=0)//辗转相除法求最大公约数
{
z=b%a;
b=a;
a=z;
}
if(z==1) printf("Naon");
else printf("Simn");
}
}
return 0;
}
余生还请多多指教!
最后
以上就是文艺蜗牛为你收集整理的VJ——A - MaratonIME helps Pablito Gym - 100985A的全部内容,希望文章能够帮你解决VJ——A - MaratonIME helps Pablito Gym - 100985A所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复