神奇的评测稽

P1226 【模板】快速幂

刚刚洛谷上又一次7,一次4
by Mosklia @ 2018-06-09 11:32:02


``` #include<cstdio> using namespace std; int main(){ long long b, m, p, a; scanf("%lld %lld %lld", &b, &m, &p); printf("%lld^%lld mod %lld=", b, m, p); a = b; // m--; while(m>0){ if(m&1) b *= a; a *= a; b %= p; a %= p; m >>= 1; } b %= p; printf("%lld", b); return 0; } ```
by Siyuan @ 2018-06-09 11:47:00


```cpp #include<iostream> #include<algorithm> #include<cmath> using namespace std; long long b,p,k,s,t; int main() { cin>>b>>p>>k; cout<<b<<"^"<<p<<" mod "<<k<<"="; s=b%k; t=1; for (int i=2;i<=p;i++) { s=s*b%k; if (s==b%k) break; t++; } p=p%t;s=1; if (p==0) p=t; for (int i=1;i<=p;i++) s=s*b%k; cout<<s; return 0; } ```
by wangzixiang666 @ 2018-06-09 11:47:08


@[Sparky_14145](/space/show?uid=67387) 帮您改了一下代码,不知道能不能过。 纯手改,没测过样例。。。
by Siyuan @ 2018-06-09 11:47:49


@[siyuan](/space/show?uid=49725) get
by Mosklia @ 2018-06-09 13:25:03


@[siyuan](/space/show?uid=49725) 谢了。。。尴尬 `scanf`格式符写错。。。
by Mosklia @ 2018-06-09 13:26:29


@[Sparky_14145](/space/show?uid=67387) 输入用`%lld`占位符啊……
by wseqwq @ 2018-07-16 11:24:36


|