题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a (mod p). That is, if we raise a to the pth power and divide by p, the remainder is a. Some (but not very many) non-prime values of p, know…
In the country there are exactly n cities numbered with positive integers from 1 to n. In each city there is an airport is located. Also, there is the only one airline, which makes m flights. Unfortunately, to use them, you need to be a regular custo…
题目大意:原题链接 题解链接 解题思路:令x=x-1代入原等式得到新的等式,两式相加,将sin()部分抵消掉,得到只含有f(x)的状态转移方程f(x+1)=f(x)+f(x-2)+f(x-3),然后用矩阵快速幂即可 #include<cstdio> #include<cstring> typedef long long ll; ; ]; ]={,,,-}; struct Mat { ll mat[][]; }res; Mat Mult(Mat a,Mat b) { Mat c;…
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 148003 Accepted Submission(s): 35976 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A…
D. Iterated Linear Function time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For…
所谓的快速幂: // 计算 m^n % k 的快速幂算法 int quickpow(int m,int n,int k) { ; ) { ) b = (b*m)%k; n = n >> ; m = (m*m)%k; } return b; } 借助于上面的函数,本题目很容易就可以解决: int main() { int n,m,x,k,data; scanf("%d%d%d%d",&n,&m,&k,&x); data=quickpow(,k,…