POJ 2115 (C Looooops)

来源:互联网 发布:淘宝企业店铺税务申报 编辑:程序博客网 时间:2024/05/20 00:15


打这个纯粹是看书看到这里,看见这个题目,就按数上的打一下,就当理解一下线性同余方程,不过打完了,还有好多疑问!!!!

表示数学真是太博大精深了。。。

代码如下:

#include<iostream>#include<cstring>#include<cstdio>using namespace std;void exgcd(__int64 a,__int64 b,__int64 &d,__int64 &x,__int64 &y){    if(b==0)    {        x=1;y=0;        d=a;return ;    }    else    {        exgcd(b,a%b,d,x,y);        __int64 temp=x;        x=y;        y=temp-(a/b)*y;    }}int main(){    __int64 x,y,m,n,l,temp,ans;    __int64 a,b,c,d,k;    while(cin>>a>>b>>c>>k &&(a+b+c+k))    {        temp=c;        c=b-a;        a=temp;        b=(__int64 )1<<k;        exgcd(a,b,d,x,y);        if(c%d != 0)        {            printf("FOREVER\n");        }        else        {            ans=x*c/d;            temp=b/d;            ans=ans%temp+temp;            cout<<ans%temp<<endl;        }    }    return 0;}


路途中。。。。

原创粉丝点击