http://acm.hdu.edu.cn/showproblem.php?pid=3270
2x + 3y = 10 15x + 35y = 67 x + y = 0
Yes. No. Yes. HINT: The first equation is true for x = 2, y = 2. So, we get, 2*2 + 3*2=10. Therefore, the output should be “Yes.”
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; int qiujie(int a,int b,int c) { int x; for(x=0; x<=c/a; x++) //枚举x可取的所有可能 { if((c-a*x)%b==0) //判断是否存在正整数y { return 1; } } return 0; } int main() { int a,b,c,i,j; char s1[16],s2[16],ch,cj; while(cin>>s1>>ch>>s2>>cj>>c) { a=b=0; for(i=0; i<strlen(s1)-1; i++) { if(s1[i]!='x') { a+=s1[i]-'0'; if(s1[i+1]!='x') a*=10; } /* a*=10; a+=s1[i]-'0';*/ } for(j=0; j<strlen(s2)-1; j++) { if(s2[j]!='y') { b+=s2[j]-'0'; if(s2[j+1]!='y') b*=10; } /* b*=10; b+=s2[j]-'0';*/ } if(s1[0]=='x')a=1; if(s2[0]=='y')b=1; if(qiujie(a,b,c)==1) printf("Yes.\n\n"); else printf("No.\n\n"); } return 0; }
杭电 3270 The Diophantine Equation,布布扣,bubuko.com
杭电 3270 The Diophantine Equation
原文:http://blog.csdn.net/u012766950/article/details/38499171