| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:牛XX....过了就好-,-In Reply To:牛XX....过了就好-,- Posted by:majia5 at 2008-10-08 18:00:49 >
无奈用将数据分段成两个I64..
后来在网上找了个ModPower的函数不会溢出.
I64 MultiMod(I64 &a, I64 b, I64 &c)
{
I64 ret = 0, d = a;
for (; b; b >>= 1, d <<= 1, d %= c)
if ((b & 1))
ret = (ret + d) % c;
return ret;
}
I64 ModPower(I64 base, I64 exp, I64 &mod)
{
I64 ret = 1;
for (; exp; exp >>= 1, base = MultiMod(base, base, mod))
if ((exp & 1))
ret = MultiMod(ret, base, mod);
return ret;
}
不过慢了点.375ms,用高精度才110ms
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator