zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    谷粒商城学习——P52商品服务-API-三级分类-新增效果
    验证码爆破总结
    利用crawlergo-to-xray实现自动化漏洞被动扫描平台搭建
    数据导入经验总结
    SQL实现2个日期之间的工作日数(MySQL)(转)
    MySQL查询所有表的数据量
    crontab定时配置(转)
    SQLyog还原会话失败
    Nginx以xxx开头的转发
    mysql备份shell脚本
  • 原文地址:https://www.cnblogs.com/xiaolitongxueyaoshangjin/p/12861291.html
Copyright © 2011-2022 走看看