F-数论

这道题考的互质,最开始题目也没有怎么读懂,后来去百度了一下,看了一些解题报告,然后才有了思路,然后就试着慢慢去写

#include <iostream>  
#include <algorithm>  
using namespace std;  
  
int gcd(int n,int m)  
{  
    while(n%m!=0)  
    {  
        int temp;  
        temp=m;  
        m=n%m;  
        n=temp;  
    }  
    return m;  
}  
  
int main()  
{  
    int t,n,m;  
    while (scanf("%d",&t)!=EOF)  
    {  
        while(t--)  
        {  
            scanf("%d%d",&n,&m);  
            if(n<m)  
                swap(n,m);  
            int flag=gcd(n,m);  
            if(flag==1)  
                printf("NO/n");  
            else  
                printf("YES/n");  
        }  
    }  
    return 0;  
}  

  

posted @ 2016-08-06 09:14  阿银家的小贰  阅读(121)  评论(0编辑  收藏  举报