标签:des style blog color os io strong for
若y<0 则不可能出现x,y同时>0的情况,因为x已经是最小的正数,若减小,则x为负,若增大,则y会减小,y为负
#include <cstdio> #include <cstring> long long a,b,c,d,x,y; long long exgcd(long long a, long long b, long long &x, long long &y) { if(b==0) { x=1; y=0; return a; } long long ret=exgcd(b, a%b, x, y); long long ty=y; y=x-a/b*y; x=ty; return ret; } int main() { while(scanf("%lld%lld%lld",&a,&b,&c)!=EOF &&(a || b || c)) { long long d=exgcd(a,b,x,y); if(c%d!=0) printf("Unquibable!\n"); else { a=a/d; b=b/d; c=c/d; x=(((x%b)*(c%b)%b)+b)%b;//x刚好大于0 即x的前一个就已经小于0 若使得y小于0 说明无解 y=(c-a*x)/b; if(y<0) { printf("Unquibable!\n"); continue; } if(x==1) { printf("1 foom and "); if(y==1) printf("1 foob for a twob!\n"); else printf("%lld foobs for a twob!\n",y); }else { printf("%lld fooms and ",x); if(y==1) printf("1 foob for a twob!\n"); else printf("%lld foobs for a twob!\n",y); } } } return 0; }
标签:des style blog color os io strong for
原文地址:http://www.cnblogs.com/Mathics/p/3905549.html