As we all know, the next Olympic Games will be held in Beijing in 2008. So the year 2008 seems a little special somehow. You are looking forward to it, too, aren't you? Unfortunately there still are months to go. Take it easy. Luckily you meet me. I…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1852 题目大意: 求2008^n的所有因子和m对k取余,然后求2008^m对k取余. 解题思路: 首先将2008因式分解,2008 = 2^3 * 251 所以2008^n = 2^(3n) * 251^(n) 因子和m =(2^(3n+1)- 1) * (251^(n+1) - 1)/ 250 m需要对k取余数.由于余数k和250可能不互质,也就是没有逆元存在,那么需要用到通用公式: 所以可以用…
hdu1852 Beijing 2008 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/65535 K (Java/Others) Total Submission(s): 502 Accepted Submission(s): 172 Problem Description As we all know, the next Olympic Games will be held in Beijing in 2008. So…
bzoj1008: [HNOI2008]越狱      O(log N)----------------------------------------------------------------------------------------------------------------------------------------- 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少…
题意: 定义函数Concatenate (1 ..N)是将所有正整数 1, 2, …, N 顺序连接起来得到的数,如concatenate(1..5)是12345,求concatenate(1...n)%m的值 思路: 矩阵快速幂,公式为 $$\left[\begin{matrix}f(n)\\n\\1\end{matrix}\right]=\left[\begin{matrix}10^k&1&1\\0&1&1\\0&0&1\end{matrix}\righ…
Beijing 2008 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others)Total Submission(s): 741    Accepted Submission(s): 291 Problem Description As we all know, the next Olympic Games will be held in Beijing in 2008. So the…
问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高位数字不为0. 因此,符合我们定义的最小的有趣的数是2013.除此以外,4位的有趣的数还有两个:2031和2301. 请计算恰好有n位的有趣的数的个数.由于答案可能非常大,只需要输出答案除以1000000007的余数. 输入格式 输入只有一行,包括恰好一个正整数n (4 ≤ n ≤ 1000). 输…
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description   Sample Input 2 Sample Output 2 Hint 1. For N = 2, S(1) = S(2) = 1. 2. The input file consists of multiple test cases.   题意是输入一个N,求N被分成1个数的结果+被分成2个数的结果+...+被分成N个数的结果,N很大   1.隔板原…
装载自:http://www.cnblogs.com/183zyz/archive/2012/05/11/2495401.html 题目让求一个函数调用了多少次.公式比较好推.f[n] = f[n-1]*f[n-2].然后a和b系数都是呈斐波那契规律增长的.需要先保存下来指数.但是太大了.在这里不能用小费马定理.要用降幂公式取模.(A^x)%C=A^(x%phi(C)+phi(C))%C(x>=phi(C)) Phi[C]表示不大于C的数中与C互质的数的个数,可以用欧拉函数来求. 矩阵快速幂也不…
题目链接: https://cn.vjudge.net/problem/POJ-1845 题目大意: 求AB的因子和 解题思路: 先将A质因数分解,然后B次方的质因数指数就是乘上B即可 这里要mod9901,但是有除法,而且不一定有逆元,所以用公式: a/b mod m 等价于 a mod (m * b) / b 所以直接求出这个即可 但是mod m*b 这个数字可能很大,就算模上之后再相乘也会溢出,所以应该用有快速加法的快速幂 #include<iostream> #include<c…