【 數論知識系統複習 】【 根據一本通提高篇總結 】【 待更 】
阿新 • • 發佈:2018-12-11
說在前面:
仔細閱讀一本通提高篇,會發現它挺齊全的,綜合了別的書籍的一些好的例題,還是很走心了。
因為已經是自己的總結了 ∴會更切合考試——實用性強,方便複習。 (關閉兩邊的廣告也OK)
歡迎━(*`∀´*)ノ亻! 因篇幅可能有點長,一點一點看也OK!質量有保證的哦!
第1章 快速冪
【 % 】
不取模 版:
LL fast_cal (LL a,LL b,LL mod){
LL ans=1;//賦值為1
while (b){
if (b&1) ans*=a;
a*=a;b>>=1;
}
return ans;
}
全程式碼:
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #define LL long long using namespace std; inline LL ll_wread(){ char c=getchar ();LL flag=1,wans=0; while (c<'0'||c>'9'){if (c=='-') flag=-1;c=getchar ();} while (c>='0'&&c<='9'){wans=wans*10+c-'0';c=getchar ();} return wans*=flag; } LL fast_cal (LL a,LL b,LL mod){ LL ans=1;//賦值為1 while (b){ if (b&1) ans=((ans%mod)*(a%mod))%mod; a=((a%mod)*(a%mod))%mod;b>>=1; } return ans%mod;//返回值時一定要取模 // 特殊資料: 1 0 1 // 即 1^0 % 1 Ans=0 } int main (){ LL a=ll_wread() ,b=ll_wread(),mod=ll_wread(); printf("%lld^%lld mod %lld=%lld\n",a,b,mod,fast_cal(a,b,mod)); return 0; }
習題解析(全):
待更新...