文章结束给大家来个程序员笑话:[M]
题意:
Define S[n] as the number of subsets of {1, 2, ...,n} that contain no consecutive integers. For each S[n], if for alli (1 ≤ i < n) gcd(S[i],
S[n]) is 1, we call that S[n] as aPrime S. Additionally, S[1] is also a Prime S. For theKth minimum Prime S, we'd like to find the
minimum S[n] which is multiple of X and not less than theKth minimum Prime S. Please tell us the corresponding (S[n] ÷X) mod M.
fibonacci数列的性子:
1.gcd(fib(n),fib(m))=fib(gcd(n,m))
证明:可以通过反证法先证fibonacci数列的恣意相邻两项一定互素,然后可证n>m时gcd(fib(n),fib(m))=gcd(fib(n-m),fib(m)),递归可
求gcd(fib(n),fib(m))=gcd(fib(k),fib(l)),最后k=l,不然继承递归。K是通过展转相减法求出,易证k=gcd(n,m),所以gcd(fib(n),fib(m))
=fib(gcd(n,m))。
2.如果fib(k)能被x整除,则fib(k*i)都可以被x整除。
3.f(0)+f(1)+f(2)+…+f(n)=f(n+2)-1
4.f(1)+f(3)+f(5)+…+f(2n-1)=f(2n)
5.f(2)+f(4)+f(6)+…+f(2n) =f(2n+1)-1
6.[f(0)]^2+[f(1)]^2+…+[f(n)]^2=f(n)·f(n+1)
7.f(0)-f(1)+f(2)-…+(-1)^n·f(n)=(-1)^n·[f(n+1)-f(n)]+1
8.f(m+n)=f(m-1)·f(n-1)+f(m)·f(n)
9.[f(n)]^2=(-1)^(n-1)+f(n-1)·f(n+1)
10.f(2n-1)=[f(n)]^2-[f(n-2)]^2
11.3f(n)=f(n+2)+f(n-2)
12.f(2n-2m-2)[f(2n)+f(2n+2)]=f(2m+2)+f(4n-2m) [ n〉m≥-1,且n≥1]
还有一个结论:
盘算(a/b)%c 其中b能整除a
如果b与c互素,则(a/b)%c=a*b^(phi(c)-1)%c
如果b与c不互素,则(a/b)%c=(a%bc)/b
对于b与c互素和不互素都有(a/b)%c=(a%bc)/b成立
#include <stdio.h> #include <iostream> #include <string.h> #include <math.h> using namespace std; typedef long long LL; const LL N=16000000; LL p[N]; bool prime[N]; LL k=1; void isprime() { LL i,j; p[0]=1; memset(prime,true,sizeof(prime)); for(i=2;i<N;i++) { if(prime[i]) { p[k++]=i; for(j=i+i;j<N;j+=i) { prime[j]=false; } } } p[1]=3;p[2]=4; } typedef struct { LL m[2][2]; }Matrix; Matrix per={1,0,0,1}; Matrix a={1,1,1,0}; Matrix multi(Matrix a,Matrix b,LL MOD) { Matrix c; LL i,j; for(i=0;i<2;i++) { for(j=0;j<2;j++) { c.m[i][j]=0; for(k=0;k<2;k++) { c.m[i][j]+=a.m[i][k]*b.m[k][j]; c.m[i][j]%=MOD; } } } return c; } Matrix matrix_mod(LL k,LL MOD) { Matrix p=a,ans=per; while(k) { if(k&1) { ans=multi(ans,p,MOD); k--; } k>>=1; p=multi(p,p,MOD); } return ans; } int main() { LL K,X,M,t,i,ret,r; isprime(); scanf("%lld",&t); while(t--) { scanf("%lld%lld%lld",&K,&X,&M); Matrix ans; for(i=p[K];;i++) { ans=matrix_mod(i-1,X); if((ans.m[0][0]%X==0)) { r=i; break; } } ans=matrix_mod(i-1,M*X); ret=ans.m[0][0]/X; printf("%lld\n",ret); } return 0; }
文章结束给大家分享下程序员的一些笑话语录: 手机终究会变成PC,所以ip会比wm更加畅销,但是有一天手机强大到一定程度了就会发现只有wm的支持才能完美享受。就好比树和草,草长得再高也是草,时间到了条件成熟了树就会窜天高了。www.ishuo.cn
--------------------------------- 原创文章 By
证明和null
---------------------------------