【模板】有理数取余

【TIMEGate】

https://www.luogu.org/problem/P2613

【解题思路】

扩欧数学

【code】

 1 #include <cstdio>
 2 #include <algorithm>
 3 #include <iostream>
 4 using namespace std;
 5 const int mod=19260817;
 6 long long a,b;
 7 int x,y;
 8 inline void read(long long &x){
 9     int f=1;x=0;char s=getchar();
10     while(s>'9'||s<'0'){
11         if(s=='-')f=-1;
12         s=getchar();
13     }
14     while(s<='9'&&s>='0'){
15         x=x*10%mod+(s-'0')%mod;
16         s=getchar();
17     }
18     x=x%mod*f;
19 }
20 inline void Exgcd(int a,int b,int &x,int &y){
21     if(b==0){
22         x=1;
23         y=0;
24         return ;
25     }
26     Exgcd(b,a%b,x,y);
27     int x2=x,y2=y;
28     x=y2;
29     y=x2-(a/b)*y2;
30 }
31 int main(){
32     read(a),read(b);
33     if(b==0){
34         printf("Angry!\n");
35         return 0;
36     }
37     Exgcd(b,mod,x,y);
38     x=(x%mod+mod)%mod;
39     printf("%lld\n",(long long)x*a%mod);
40     while(1);
41     return 0;
42 }

 

posted @ 2019-09-07 15:22  GTR_PaulFrank  阅读(126)  评论(0编辑  收藏  举报