NYOJ144_小珂的苦恼_C++
题目:http://acm.nyist.net/JudgeOnline/problem.php?pid=144
用扩展欧几里得定理判断是否有解即可,然后记得打上读入优化
扩展欧几里得算法:http://www.cnblogs.com/hadilo/p/5914302.html
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #include<cmath> 5 #include<iostream> 6 #include<algorithm> 7 #define N putchar('N'),putchar('o'),putchar('\n') 8 #define Y putchar('Y'),putchar('e'),putchar('s'),putchar('\n') 9 using namespace std; 10 11 inline int gcd(int x,int y) 12 { 13 return !y?x:gcd(y,x%y); 14 } 15 inline void read(int &re) 16 { 17 char ch=getchar(); 18 re=0; 19 while (ch>='0'&&ch<='9') 20 { 21 re=re*10+ch-'0'; 22 ch=getchar(); 23 } 24 } 25 int main() 26 { 27 int n,a,b,c,r; 28 read(n); 29 while (n>0) 30 { 31 n--; 32 read(a); 33 read(b); 34 read(c); 35 r=gcd(a,b); 36 if (c%r) N; 37 else Y; 38 } 39 }
版权所有,转载请联系作者,违者必究
QQ:740929894