洛谷 P1082 同余方程

水题,扩展欧几里得求解即可

错误原因:扩展欧几里得写炸

#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL;
LL x,y;
LL a,b;
LL exgcd(LL a,LL b)
{
    if(b==0)
    {
        x=1;y=0;
        return a;
    }
    else
    {
        LL t1=exgcd(b,a%b),t=x;
        x=y;
        y=t-a/b*y;
        return t1;
    }
}
int main()
{
    scanf("%lld%lld",&a,&b);
    if(exgcd(a,b)==1)
    {
        LL t1=floor(-(double)x/b)+1;
        printf("%lld",t1*b+x);
    }
    return 0;
}
posted @ 2017-11-05 22:00  hehe_54321  阅读(176)  评论(0编辑  收藏  举报
AmazingCounters.com