Fast Multiply test Comparison procedure:
#include <bits/stdc++.h>using namespaceStd;typedefLong LongLl;ll Rd () {returnRand () | (LL (rand ()) << +);} ll Md;ll Mul1 (ll x,ll y) {x%=md;y%=MD; ll T=x*y-ll ((Long Double) x/md*y+0.5)*MD; returnt<0? t+Md:t;} ll Mul2 (ll X,ll y) {x%=md;y%=MD; ll T=x*y-ll ((Long Double) x*y/md+0.5)*MD; returnt<0? t+Md:t;} ll Mul3 (ll X,ll y) {x%=md;y%=MD; ll T=x*y-ll ((Long Double) x/md*y+1e-8)*MD; returnt<0? t+Md:t;} ll Mul0 (ll X,ll y) {return__int128 (x) *y%MD;} ll A, B;intMain () {intt=0; Srand (3254244); while(1) {T++; ll a=rd (), b=Rd (); MD=rd ();//%ll (1E18); //cout<<a<< ' <<b<< ' <<md<< ' \ n ';ll T1=mul1 (A, B), T2=mul0 (A, b);//You can change the MUL1 to Mul2/mul3//cout<<t1<< ' <<t2<< ' \ n '; if(t1!=T2) {printf ("%d\n", T); Puts ("Test"); intT;cin>>T; } //int t;cin>>t; } return 0;}
View Code
After some tests, it can be found that the MUL3 effect is the worst (in the modulus >=1e17, 100000 groups within the pot); it should be 1e-8.
Mul2 effect is not mul1 good (modulus does not set an additional upper limit, 100000 groups within the pot; upper limit 1e18, 20 seconds not out of the pot)
MUL1 the best effect (modulus does not set an additional upper limit, 20 seconds not out of the pot)
The reason is not known ...
Fast ride?