HNU 11720 God Created The Integers
生活随笔
收集整理的這篇文章主要介紹了
HNU 11720 God Created The Integers
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
原題傳送:http://acm.hnu.cn/online/?action=problem&type=show&id=11720&courseid=0
對(duì)于這條式子:
和下面的式子是等價(jià)的:
Sp = (p2 - 1) / 2 - (p - 1) / 4
那么求出Sp后有rp*Sp ≡ 1 (mod p),用擴(kuò)展GCD求出rp就行了。
View Code 1 #include <stdio.h> 2 #include <string.h> 3 4 typedef __int64 LL; 5 LL p, s; 6 7 LL exgcd(LL a, LL b, LL &x, LL &y) 8 { 9 LL d, t; 10 if(b == 0) 11 { 12 x = 1, y = 0; 13 return a; 14 } 15 d = exgcd(b, a % b, x, y); 16 t = x, x = y, y = t - (a / b) * x; 17 return d; 18 } 19 20 void solve(int cas) 21 { 22 s =(p * p - 1) / 24 - (p - 1) / 4; 23 LL x, y; 24 exgcd(s, p, x, y); 25 printf("Case #%d: %I64d\n", cas, (x + p) % p); 26 } 27 28 int main() 29 { 30 int t, cas; 31 while(scanf("%d", &t) != EOF) 32 { 33 for(cas = 1; cas <= t; cas ++) 34 { 35 scanf("%I64d", &p); 36 solve(cas); 37 } 38 } 39 return 0; 40 }?
轉(zhuǎn)載于:https://www.cnblogs.com/huangfeihome/archive/2012/10/06/2713070.html
總結(jié)
以上是生活随笔為你收集整理的HNU 11720 God Created The Integers的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#基础系列第五篇
- 下一篇: TempDB为什么要根据CPU数目来决定