[校内赛3-1][题解]folder

题目其实非常裸……

就是让你求ax≡c(mod b)中x的最小正整数解

裴蜀定理判断是否有解(即信息真假)

然后exgcd解方程

输出有坑不过我相信你们没有人会踩因为我已经提示了

std:

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cmath>
 4 #include<ctime>
 5 #include<cstring>
 6 #include<iostream>
 7 #include<algorithm>
 8 #include<stack>
 9 #include<queue>
10 #include<vector>
11 #include<bitset>
12 #include<set>
13 #include<map>
14 #define LL long long
15 #define rg register
16 #define us unsigned
17 #define eps 1e-6
18 #define INF 0x3f3f3f3f
19 #define ls k<<1
20 #define rs k<<1|1
21 #define tmid ((tr[k].l+tr[k].r)>>1)
22 #define nmid ((l+r)>>1)
23 #define Thispoint tr[k].l==tr[k].r
24 #define pushup tr[k].wei=tr[ls].wei+tr[rs].wei
25 using namespace std;
26 inline void Read(LL &x){
27     LL f=1;
28     char c=getchar();
29     x=0;
30     while(c<'0'||c>'9'){
31         if(c=='-')f=-1;
32         c=getchar();
33     }
34     while(c>='0'&&c<='9'){
35         x=(x<<3)+(x<<1)+c-'0';
36         c=getchar();
37     }
38     x*=f;
39 }
40 
41 LL a,b,c,x,y;
42 LL Gcd(LL a,LL b){
43     return b==0?a:Gcd(b,a%b);
44 }
45 void exgcd(LL a,LL b,LL &x,LL &y){
46     if(b==0){
47         x=1,y=1;
48         return;
49     }
50     LL x_1,y_1;
51     exgcd(b,a%b,x_1,y_1);
52     x=y_1;
53     y=x_1-(a/b)*y_1;
54 }
55 int main(){
56     freopen("folder.in","r",stdin);
57     freopen("folder.out","w",stdout);
58     Read(a),Read(b),Read(c);
59     LL g=Gcd(a,b);
60     if(c%g!=0){//裴蜀定理判断 
61         printf("N0\nO\n");
62         return 0;
63     }
64     exgcd(a,b,x,y);
65     LL s=b/Gcd(a,b);//此处取模可以参照之前的课件,这里不再赘述 
66     printf("YE5\n%lld\n",((x*c/g)%s+s)%s);
67     return 0;
68 }
My Beautiful Code

猜你喜欢

转载自www.cnblogs.com/juruoajh/p/12445076.html
3-1