随笔分类 -  ACM_数论

Lucas定理及其应用
摘要: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... 阅读全文

posted @ 2014-09-28 19:39 rootial 阅读(443) 评论(0) 推荐(0)

Codeforces 258 Div2
摘要:A题,n*m根木棍,相交放置,轮流取走相交的两根,最后谁不能行动,则输掉。min(n,m)&1 为1则先取者赢。B题,给定一个长度为n,且各不相同的数组,问能否通过交换连续一段L....R使得变成单调递增。如果一开始就是递增的,那么直接输出L。。。R就是1 1,交换一个就行了;否则判断中间是否有且一... 阅读全文

posted @ 2014-07-26 02:10 rootial 阅读(199) 评论(0) 推荐(0)

UVALive 6602 Counting Lattice Squares
摘要:给定一个n*m的网格,求面积为奇数的正方形有多少个.首先是n*m个面积为1的,然后剩下的要么是边长为奇数,要么被这样一个奇数边长所包围。原因如下:对于一个边长不平行于坐标抽的正方形,其边长一定是某个长方形的对角线,而且长方形长宽a,b一定是一奇数,一偶数,这样area = a^2+b^2才是奇数。所以可以对任何奇数i #include #include #include #include #include #include #include #include #include #include #include #include #include #define esp 1e-3#defin. 阅读全文

posted @ 2014-02-17 16:19 rootial 阅读(445) 评论(0) 推荐(0)

UVA 11426 GCD Extrme (Ⅲ)
摘要:给定一个整数N(1 2 #define N 4000010 3 #define M 4000000 4 5 int phi[N]; 6 typedef long long ll; 7 ll a[N]; 8 9 void solve(void)10 {11 int i,j;12 for(i=2;i<=M;i++)13 {14 if(phi[i]==i)//phi[i]为i表示该数的欧拉函数值还没有求过,也就是该数为素数。15 {16 for(j=i;j<=M;j+=i)//筛法求欧拉函数值,17 ... 阅读全文

posted @ 2013-07-28 16:18 rootial 阅读(221) 评论(0) 推荐(0)

Fibonacci数列对任何数取模都是一个周期数列
摘要:题目是要求出斐波那契数列n项对一个正整数取模,那么可以把斐波那契数列取模后得到的数列周期求出来。比如下面一个题目:求出f[n]的后4位,先求出数列对10000取模的周期,然后再查找即可。 1 #include 2 #define N 15000 3 #define MOD 10000 4 int a[N]; 5 int main(void) 6 { 7 int i,n; 8 a[0]=0; 9 a[1]=1;10 for(i=2;i#define MOD 10000void AN(int a[][2],int b[][2]){ int a1,a2,a3,a... 阅读全文

posted @ 2013-07-23 13:32 rootial 阅读(774) 评论(0) 推荐(0)

CF_Lucky Sum
摘要:幸运数字的定义是这样:仅含4和7且不比n小的数为n的幸运数字。输入范围l,r要求输出这个范围内的数字的幸运数字之和。代码: 1 #include 2 #define N 1024 3 typedef long long ll; 4 ll a[N+1]; 5 ll f(ll n) 6 { 7 if(n==0) 8 return 0; 9 int i;10 ll ans=0;11 for(i=1;i<=N;i++)12 {13 if(a[i]<n)14 ans+=a[i]*(a[i]-a[i-1]);1... 阅读全文

posted @ 2013-07-22 18:06 rootial 阅读(209) 评论(0) 推荐(0)

CF_225B _Well-known Numbers
摘要:Numbersk-bonacci (kis integer,k > 1) are a generalization of Fibonacci numbers and are determined as followsF(k, n) = 0, for integern,1 ≤ n k.Note that we determine thek-bonacci numbers,F(k, n), only for integer values ofnandk.You've got a numbers, represent it as a sum of several (at least t 阅读全文

posted @ 2013-07-22 14:32 rootial 阅读(278) 评论(0) 推荐(0)

导航