• A


    ♬ 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 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

    Input
    2
    2 4
    3 5
    Output
    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
    ");
    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
    ");
    36             }
    37             else
    38             {
    39                 printf("Sim
    ");
    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;
    }
  • 相关阅读:
    Spring Boot整合JPA
    Emmet Cheat Sheet All In One
    CCTV《航拍中国》系列视频 All In One
    上海市税务局服务 All In One
    CCTV 天气预报 All In One
    Next.js Tutorials All In One
    如何使用 GitHub Actions 发布 Gatsby 静态网站 All In One
    GitHub Code Security & Code Scanning All In One
    数字滚动显示组件 All In One
    Gatsby plugins All In One
  • 原文地址:https://www.cnblogs.com/xiaolitongxueyaoshangjin/p/12861291.html
Copyright © 2020-2023  润新知