10 2014 档案
摘要:先介绍两个:大数的GcdStein+欧几里德 function stein(a,b:int64):int64;begin if a>1,b>>1)>1,b)); if (b and 1)=0 then exit(stein(a,b>>1)); exit(stein((...
阅读全文
摘要:要求a^b^c mod p保证gcd(c,p)=1用费马小定理b:=quick_mod(b,c,p-1);c:=quick_mod(a,b,p);a^c mod p=a^(c mod phi(p)) mod p而素数的phi函数是无需计算的,即p-1推广到多个,依次降幂即可。不断应用快速幂。var ...
阅读全文
摘要:素数定理:记为小于等于的素数个数,那么有定理:设,,那么有定理:设,,那么定理:设,那么的值为(1)为素数,那么答案就是(2)有多个素因子,那么答案就是(3)只有一个素因子,那么答案就是该素因子定理:设为Fib数,那么有定理:给定两个互素的正整数和,那么它们最大不能组合的数为,不能组合的数的个数为定...
阅读全文
摘要:给定同余式,求它在内的所有解,其中总是素数。分析:解本同余式的步骤如下 (1)求模的一个原根 (2)利用Baby Step Giant Step求出一个,使得,因为为素数,所以有唯一解。 (3)设,这样就有,其中,那么得到。 (4)求出所有的,可以知道一共有个解,我们求出所有的,然后排个序即...
阅读全文
摘要:题目描述最少把1~n 分成多少组,可以使得每组的数的和为素数输入有多组数据第一行是一个数T,表示数据组数每组数据共1 行,为正整数n输出有T 行,每行为该情况的最少组数,无法分组时,输出-1样例输入12样例输出1哥德巴赫猜想裸题首先如果sum(n)是偶数,即两个素数之和,writeln(2)如果su...
阅读全文
摘要:斐波那契级数除以N会出现循环,此周期称为皮萨诺周期。下面给出证明必然会出现循环这是基于下面事实:1.R(n+2)=F(n+2)modP=(F(n+1)+F(n))modP=(F(n+1)modp+F(n)modp)modp2.斐波那契数列的最大公约数定理:gcd(F(m),F(n))=F(gcd(m...
阅读全文
摘要:转自某大牛。Fibonacci数列:F(0)=1 , F(1)=1 , F(n)=F(n-1)+F(n-2)我们以前快速求Fibonacci数列第n项的方法是 构造常系数矩阵(一) Fibonacci数列f[n]=f[n-1]+f[n-2],f[1]=f[2]=1的第n项快速求法(不考虑高精度)解法...
阅读全文
摘要:题目大意如下:给定一个序列,每个序列有值xi,现给定t个数列,对于每个长n的数列,求一段[l,r]使 [r-l+1]*gcd(l,r)最大,gcd(l,r)指的是该连续区间的最大公约数。不难想到n^3,n^2logx,n^2的暴力吧n^3DP,n^2logx暴力枚举,n^2DP可以这样考虑,每次我对...
阅读全文
摘要:const maxm=1e100; maxn=1000001; var f,x,p,c,sum,cost:array[0..maxn] of int64; q:array[0..maxn] of longint; n,i,h,t:longint; fun...
阅读全文
摘要:program candy bzoj1062;const maxc=1000100; maxm=4010; maxn=2010;var n,len,m,i,p,t,l,r,c,d,q:longint; s:array[0..1,0..maxn,0..maxm] of lon...
阅读全文
摘要:program bzoj1023;uses math;const inf=1000000000; maxn=50005; maxm=20000005; type edge=record togo,next:longint;end; var n,m,cnt,ind,ans...
阅读全文
摘要:program bzoj1022;var t,n,i,ans,k,j,k1,k2:longint; bo:boolean;begin read(t); for k:=1 to t do begin read(n); ans:=0; k2:=0; ...
阅读全文
摘要:program bzoj1018;type node=array [0..5] of boolean; pair=array [0..1] of boolean;var tot,c,i,j,k,x1,y1,x2,y2:longint; ans:boolean; ch:char; x,y,...
阅读全文
摘要:program bzoj1015;{$inline on}const maxn=400001;type node=record togo,next:longint;end;var tot,n,m,d,cnt:longint; father,head,q,ans:array [0..max...
阅读全文
摘要:program bzoj3196;const inf=100000000; maxn=200001; maxm=3000001;var n,m,time,temp:longint; root,a:array [0..maxn] of longint; left,right,r...
阅读全文
摘要:program bzoj1828;const maxn=100001; check=10000000; type node=record l,r,s,a:longint;end;var t:array [0..maxn*5] of node; a,b,c:array [0.....
阅读全文
摘要:var f:array[0..10,0..90,0..600] of int64; a:Array[0..600] of longint; count:array[0..600] of longint; ans:int64; n,m:longint; procedure init;var...
阅读全文
摘要:一、前言质因数分解,是一个在算法竞赛里老生常谈的经典问题。我们在解决许多问题的时候需要用到质因数分解来辅助运算,而且质因数分解牵扯到许许多多经典高效的算法,例如miller-rabin判断素数算法,rho启发式搜索质因数分解算法等。在此文里,我要介绍的就是miller-rabin算法以及rho启发式...
阅读全文
摘要:先说下我的代码风格(很丑,勿喷) maxn表示最大空间的四倍 tree数组表示求和的线段树 delta表示增减的增量标记 sign表示覆盖的标记 delta,sign实际上都是lazy标志 pushdown表示标记下传 pushup表示标记上传(即求和,区间最值) update表示...
阅读全文

浙公网安备 33010602011771号