模乘

2019-04-13 11:39发布

#include"iostream" using namespace std; long long mul1(long long a,long long b,long long mod) { long double x; long long c; long long r; if (a >= mod) a %= mod; if (b >= mod) b %= mod; x = a; c = x * b / mod; r = (a * b - c * mod) % mod; return r < 0 ? r + mod : r; } long long mul2(long long a,long long b,long long mod) { a%=mod; b%=mod; long long res=0,base=a; while(b) { if(b&1)res=(res+base)%mod; base=(base*2)%mod; b>>=1; } return res; } long long mul3(long long a,long long b,long long mod)///tao shen de gong shi { return (a*b-(long long)(a/(long double) mod * b + 1e-3)* mod + mod) % mod; } int main() { long long a=1e18+7,b=1e17+38,mod=1e18+79; // for(int i=1;i<=100000000;i++) cout<mod)<<" "; cout<mod)<<" "; cout<mod)<<" "; }