int quick_pow(int a, int n){ int ans = 1; while (n) { if (n & 1) { ans = (long long )ans * a % inf; } n >>= 1...
分类:
其他好文 时间:
2014-10-10 00:35:11
阅读次数:
218
时间限制:0.5s空间限制:6M题意: 给出长n(n#include #include using namespace std;struct Mat { int mat[100][100];} mx;int pow[109];int n, m, mod, len;Mat operator ...
分类:
其他好文 时间:
2014-10-09 13:21:33
阅读次数:
183
这道题我的写法和别人可能不一样,总体思路是一样的
第一步就是判断n的情况,如代码所示
我是将指数n转化成二进制,比如说: 3^45
45的二进制是101101
从左到右扫一遍,跳过第一位。
如果位是0,那么就将结果平方,也就是乘自己。
如果位是1,那么除了要将结果平方,还要再乘一次x
这个的原理是根据指数的性质,如果n=10(二进制),相当于2,如果n左移一位,就是再*2,也...
分类:
其他好文 时间:
2014-10-06 14:11:00
阅读次数:
140
题目最近比赛的题目好多签到题都是找规律的考验智商的题目啊,,,我怎么越来越笨了,,,,通过列举,可以发现规律:从左往右按位扫这个数:当数的长度大于1时:当首位大于3时,答案就是4*4*4*……*4*3(即pow(4,后面的长度-1)*3);否则,则是 首位的数字*4*4*4*……*4*3;当数的长度...
分类:
其他好文 时间:
2014-10-05 21:26:48
阅读次数:
257
整体在一个命名空间POW中,使用时应加上POW :: **** 1namespacePOW{2typedefintt;//使用时可将"int"修改为矩阵中存储的数据类型3consttMOD=t(1e9+7);//改为快速幂要求的模数45template6Tpowmod(Ta,intn,Tmod){....
分类:
其他好文 时间:
2014-10-04 00:50:45
阅读次数:
244
题目来源:POJ 1046 Color Me Less题目大意:每一个颜色由R、G、B三部分组成,D=Math.sqrt(Math.pow((left.red - right.red), 2)+ Math.pow((left.green - right.green), 2)+ Math.pow((l...
分类:
其他好文 时间:
2014-09-30 02:39:52
阅读次数:
339
最近看到这样的一个题目求X的N次方,自己想了一些解决办法,记录一下留作日后参考...
分类:
其他好文 时间:
2014-09-29 19:34:01
阅读次数:
129
Lucas定理这里有详细的证明。其实就是针对n, m很大时,要求组合数C(n, m) % p, 一般来说如果p 2 #include 3 #include 4 using namespace std; 5 6 #define N 100010 7 8 long long mod_pow(i...
分类:
其他好文 时间:
2014-09-28 22:10:55
阅读次数:
192
直接lucas降到10w以内搞组合数
#include
#include
typedef __int64 LL;
LL f[110010];
LL pow(LL a, LL b, LL c)
{
LL ans = 1;
while(b)
{
if(b&1)
ans = (ans*a) % c;
b >>= 1;
a = (a*a) % c;
}
return an...
分类:
其他好文 时间:
2014-09-28 21:49:55
阅读次数:
216
BigInteger / BigDecimal / string 一些常用的函数:加 add减 substract乘 multiply除 divid取余 mod次幂 pow(int)比较 compareTo / equals判断是否某string开头(是否0开头) startsWith("0").....
分类:
编程语言 时间:
2014-09-28 00:18:50
阅读次数:
323