求a乘b对p取模的值,其中 1<=a,b,p<=pow(10,18)
//#pragma GCC optimize(2) #pragma comment(linker, "/STACK:10240000,10240000") #include #include #include #include #include<string> #include #include #include<set> #include #include #include #include #include #include #include #include #include //accumulate #define endl "\n" #define fi first #define se second #define forn(i,s,t) for(int i=(s);i<(t);++i) #define mem(a,b) memset(a,b,sizeof(a)) #define rush() int MYTESTNUM;cin>>MYTESTNUM;while(MYTESTNUM--) #define debug(x) printf("%d\n",x) #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f #define mp make_pair #define pb push_back #define sc(x) scanf("%d",&x) #define sc2(x,y) scanf("%d%d",&x,&y) #define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z) #define pf(x) printf("%d\n",x) #define pf2(x,y) printf("%d %d\n",x,y) #define pf3(x,y,z) printf("%d %d %d\n",x,y,z) #define ll long long #define ull unsigned long long #define dd double #define pfs puts("*****") #define pfk(x) printf("%d ",(x)) #define kpf(x) printf(" %d",(x)) #define pfdd(x) printf("%.5f\n",(x)); #define pfhh printf("\n") using namespace std; const ll P=1e9; ll mul(ll a, ll b){ll ans = 0;for(;b;a=a*2%P,b>>=1) if(b&1) ans=(ans+a)%P;return ans;} ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;} ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;} const int maxn=550; inline int read() { int X=0,w=0; char ch=0; while(!isdigit(ch)) {w|=ch=='-';ch=getchar();} while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); return w?-X:X; } ll mmul(ll a,ll b,ll p){ ll ans=0; for(;b;b>>=1){ if(b&1) ans=(ans+a)%p; a=a*2%p; } return ans; } ll mmul2(ll a,ll b,ll p){ a%=p, b%=p; ll c=(long double)a*b/p; ll ans=a*b-c*p; if(ans<0) ans+=p; else if(ans>p) ans-=p; return ans; } signed main() { while(1){ ll a,b,p; scanf("%lld%lld%lld",&a,&b,&p); ll ans=mmul2(a,b,p); printf("%lld\n",ans); } return 0; }