一.常用算法
文中代码大量来自ACM算法模板 · 一些常用的算法模板-模板合集(稍加修改)
1.1 快速幂
1 ll qpow(ll x, ll n , ll mod) 2 { 3 ll ans=1; 4 while(n){ 5 if(n&1){ 6 ans=(ans*x)%mod; 7 n--; 8 } 9 x=(x*x)%mod; 10 n>>=1; 11 } 12 return ans; 13 }
1.2 gcd
1 ll gcd(ll a,ll b){ 2 return b==0?a:gcd(b,a%b); 3 }
1.3 大数乘法
1 long long quick_multiply(long long a, long long b, long long mod) { 2 long long result = 0; 3 while (b) { 4 result = (result + (b % 2 * a) % mod) % mod; 5 a = a * 2 % mod; 6 b = b / 2; 7 } 8 }
1 for(i=0; i<LA-1; i++) 2 for(j=0; j<LB-1; j++) 3 c[i+j]+=a[i]*b[j]; 4 5 for(i=0; i<LA+LB; i++) 6 if(c[i]>=10) 7 { 8 c[i+1]+=c[i]/10; 9 c[i]%=10; 10 }
1 //https://www.cnblogs.com/king-ding/p/bigIntegerMul.html 2 #include<stdio.h> 3 #include<string.h> 4 #include<malloc.h> 5 6 #define and && /**************/ 7 #define or || /* python风格 */ 8 #define not ! /* */ 9 #define Int(X) (X - '0') /**************/ 10 11 int *multiBigInteger(const char *, const char *); 12 int checkNum(const char *); 13 14 int main(void) 15 { 16 char num1[100] = {'