标签:scanf after net ble else HERE span OWIN amount
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:
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 a i e b i 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 a i and b i share a common ancestor and "Nao" otherwise.
Example
2
2 4
3 5
Sim
Nao
1 计科1902逄明宝 2020/5/9 19:55:59 2 3 #include <bits/stdc++.h> 4 5 using namespace std; 6 7 int main() 8 { 9 int t; 10 scanf("%d",&t); 11 while(t--) 12 { 13 long long int a,b,l,x; 14 scanf("%lld %lld",&a,&b); 15 if(a<b) 16 { 17 l=b; 18 b=a; 19 a=l; 20 } 21 if(a%b==0) 22 { 23 printf("Sim\n"); 24 } 25 else 26 { 27 while(a%b!=0) 28 { 29 x=a%b; 30 a=b; 31 b=x; 32 } 33 if(x==1) 34 { 35 printf("Nao\n"); 36 } 37 else 38 { 39 printf("Sim\n"); 40 } 41 } 42 } 43 return 0; 44 }
求最大公约数
辗转相除法
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d",&n); while(n--) { int a,b,c; scanf("%d %d",&a,&b); if(a<b) { c=a; a=b; b=c; } if(a%b==0) printf("%d",b); else { int x; while(a%b!=0) { x=a%b; a=b; b=x; } if(x==1) printf("No"); else printf("%d",b); } } return 0; }
A - MaratonIME helps Pablito 最大公倍数
标签:scanf after net ble else HERE span OWIN amount
原文地址:https://www.cnblogs.com/xiaolitongxueyaoshangjin/p/12861291.html