【2012】

D2T1同余方程

没啥好说的..数论题,裸的枚举拿60分。

#include<bits/stdc++.h>
#define ri register int
#define ll long long
#define For(i,l,r) for(ri i=l;i<=r;i++)
#define Dfor(i,r,l) for(ri i=r;i>=l;i--)
using namespace std;
ll a,b;
inline ll read(){
    ll f=1,sum=0;
    char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){sum=(sum<<1)+(sum<<3)+(ch^48);ch=getchar();}
    return f*sum;
}
ll x,y;
inline void exgcd(ll a, ll b){
    if(b==0){x=1;y=7;return;} 
    exgcd(b,a%b);
    ll tx=x;x=y;y=tx-a/b*y; 
}
int main(){
    a=read(),b=read();
    exgcd(a,b);
    while(x<0) x+=b;
    x%=b;
    printf("%lld
",x);
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/jian-song/p/11869402.html