求不定方程初始解{ax+by=c,a,b,c∈Z…

来源:互联网 发布:如何用sql建立数据库 编辑:程序博客网 时间:2024/05/16 05:35
var  a,b,c,x,y,gcd:longint;function getroot(a,b,c:longint;varx,y,gcd:longint):boolean;var  tx,ty:longint;{记得设一个临时存下一层递归的变量}begin  if b=0 then    if c mod a=0 then     begin       gcd:=a;       x:=c div a;       y:=0;       getroot:=true;     end    elsegetroot:=false  else    if getroot(b,a modb,c,tx,ty,gcd) then     begin       x:=ty;       y:=tx-(a div b)*ty;       getroot:=true;     end    else     getroot:=false;end;begin  read(a,b,c);  if getroot(a,b,c,x,y,gcd) then writeln(x,'',y);end.


原创粉丝点击