Chef and Prime Divisors Problem code: CHAPD (GCD问题)

题目大意:

给定两个数,n,m,找到如果m的所有质因数可以被n,整处的话输出"Yes",OR   "No".

text:

3
120 75
128 16
7 8

Output:
Yes
Yes
No

直到,最大公约数为1,时看后者是否为1,即可。

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<queue>
#define inf 0x3f3f3f3f
using namespace std;
long long gcd(long long n,long long m)
{
   return  m==0?n:gcd(m,n%m);//忘了加return WA了几次。。
}
int main()
{
    long long n,m,cla;
    cin>>cla;
    while(cla--)
    {
        cin>>n>>m;
        long long k=gcd(n,m);
        while(k>1)
        {
            m=m/k;
            k=gcd(n,m);
        }
        if(m==1)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-12 11:24:54

Chef and Prime Divisors Problem code: CHAPD (GCD问题)的相关文章

HDU 1016:Prime Ring Problem

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 25156    Accepted Submission(s): 11234 Problem Description A ring is compose of n circles as shown in diagram. Put natural num

HDU 1016 Prime Ring Problem(素数环问题)

传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 63806    Accepted Submission(s): 27457 Problem Description A ring is compos

hdu 1016 Prime Ring Problem DFS解法 纪念我在杭电的第一百题

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29577    Accepted Submission(s): 13188 Problem Description A ring is compose of n circles as shown in diagram. Put natural num

[2016-02-19][UVA][524][Prime Ring Problem]

UVA - 524 Prime Ring Problem Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers  into each circle separately, and the

HDU 1016 Prime Ring Problem 题解

Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle should always be 1

[ACM] 1016 Prime Ring Problem (深度优先搜索)

Prime Ring Problem Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle

uva 524 prime ring problem——yhx

  Prime Ring Problem  A ring is composed of n (even number) circles as shown in diagram. Put natural numbers into each circle separately, and the sum of numbers in two adjacent circles should be a prime. Note: the number of first circle should always

HDU 1016 Prime Ring Problem(深搜)

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 32872    Accepted Submission(s): 14544 Problem Description A ring is compose of n circles as shown in diagram. Put natural num

HDOJ-1016 Prime Ring Problem【DFS】

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 47217    Accepted Submission(s): 20859 Problem Description A ring is compose of n circles as shown in diagram. Put natural numb