
组合数学数论
文章平均质量分 58
plusplus7
萌系大学生一枚。。。。
展开
-
POJ 3252 Round Numbers
这题用组合数学来做,思路很好想,但是实现的时候细节台繁杂了,所以很容易出错。。首先[a,b]可以看成[0,b+1)-[0,a)。剩下的就用组合数学的知识很容易就能得出答案了。#include #include #include using namespace std;int C[35][35];void init(){ int i,j; for (i=0;原创 2012-12-06 22:13:48 · 405 阅读 · 0 评论 -
POJ 1106 Transmitters
给定一些点,和一个圆心坐标,求一个以这个点为圆心的半圆能最多能圈下多少点。#include #include #include #include using namespace std;#define hPI 1.5707963267949#define eps 1e-8struct point{ double x; double y;};double cr原创 2013-03-02 23:08:22 · 576 阅读 · 0 评论 -
收集整理威尔逊定理的证明
在求解BNUOJ 1093 YAPTCHA时,用到了威尔逊定理。在这里收集整理一下证明威尔逊定理的方法。先说从题意出发吧。这道题是给定一个式子再给若干个n,让你求出Sn的值。(1暴力肯定是不行的。所以考虑数论的方法。 当3k+7不是素数时,可以得到((3k+6)!+1)/(3k+7)=[(3k+6)!/(3k+7)],此时括号内的值为0. 当原创 2013-03-06 16:02:49 · 10502 阅读 · 0 评论 -
BNUOJ 1095 Business Cards
CEPC 2008感觉这题看了题解也不太懂。。#include #include #include using namespace std;int gcd(int a,int b){ int t; if (a < b) { t=a; a=b; b=t; } if (b原创 2013-02-02 14:20:07 · 576 阅读 · 0 评论 -
BNUOJ 1093 YAPTCHA
CEPC 2008应用Wilson定理,可知当p为素数时,表达式值为1,否则为0。所以筛出素数表,扫一篇就可以了。#include #include #include using namespace std;int ans[1200000];#define MAXN 3300000bool prime[MAXN];void getPrime(){原创 2013-02-02 14:15:54 · 624 阅读 · 0 评论 -
BNUOJ 1098 Tower
CEPC 2008题目简化一下,就是给出公式a[n]=2*a[2]*a[n-1]-a[n-2],求S[n]=sigma(a[n]^2),n有10^9,而case数也是达到了10^5。对于这样的常系数线性递推式,用这篇论文里的第三种方法就能够轻松解决。构造矩阵使用快速幂|4*a[2]^22*a[2] 1 4*a[2]^2||-4*a[2] -1 0原创 2013-02-02 14:13:09 · 472 阅读 · 0 评论 -
POJ 2140 Herd Sums
推出个数学式子~#include #include #include #include using namespace std;int main(){ int n,i,j,s,k,cnt; scanf("%d",&n); cnt=0; for (i=1; i<=sqrt(2*n); i++) { j=2原创 2013-01-29 20:04:50 · 506 阅读 · 0 评论 -
POJ 1942 Paths on a Grid
看题很容易想到一个递推式,但是题目给出的数据很大,所以,虽然题目保证答案You may safely assume that this number fits into a 32-bit unsigned integer.。 递推肯定会超时的额。得另外想个办法。 把递推式写下来,可以发现f(n,m)=C(n+m,n);所以其实就是让你输出C(n+m,n)。原创 2012-12-20 22:38:08 · 4116 阅读 · 0 评论 -
POJ 1850 Code
组合数学题。 给你一个序列,并给其编号,如a - 1 b - 2 ... z - 26 ab - 27 ... az - 51 bc - 52 ... vwxyz - 83681 题目给出一个字符串,求这个字符串的编号。若不合法 (字符不递增),则输出0. 解法:求出排在这个字符串之前有多少个串原创 2012-12-20 15:41:52 · 397 阅读 · 0 评论 -
POJ 1019 Number Sequence
数学题。11212312341234512345612345671234567812345678912345678910123456789101112345678910求这个数列的第n位上的数是多少。#include #include #include #include using namespace std;long long a[32000],s[32000],up;原创 2012-12-20 16:27:34 · 468 阅读 · 0 评论 -
SGU 113 Nearly prime numbers
此题给定一个n,让你判断这个数是否是两个素数的乘积。因为n是10^9,所以用2到sqrt(n)去作为除数,看能否被n整除,如果能,判断商是不是一个素数,如果商是素数,输出yes,否则输出no。 #include #include #include #include using namespace std;bool Check(int n){ int原创 2012-12-16 20:32:45 · 546 阅读 · 0 评论 -
SGU 116 Index of super-prime
定义了一种数super prime,数的本身是一个素数,且在素数表里的下标(从1开始)也是一个素数。然后给定一个n,求用最少的superprime相加得到n的方法。 解法,因为数据很小,Number is not more than 10000. 在10000内的super prime也很少,只有201个,所以可以直接本地打表得出。随后就是一个很简单的背包。#includ原创 2012-12-16 20:38:58 · 896 阅读 · 0 评论 -
POJ 3292 Semi-prime H-numbers
H-number是指形如4n+1(n>=0)的整数,后又定义了好几种数。水题。#include #include #include #include using namespace std;#define N 1000002bool NotaHprime[N],IsaHsemiprime[N];int ans[N];int main(){ in原创 2012-12-26 13:03:15 · 435 阅读 · 0 评论 -
POJ 2635 The Embarrassed Cryptographer
给一个大数K和一个数L(L高精度求模,用10进制的会TLE,所以尽量把数往大进制转换。#include #include #include #include #define MAXN 2000010using namespace std;bool prime[MAXN];void getPrime(){ int i, j; prime[0原创 2012-12-26 13:06:57 · 435 阅读 · 0 评论 -
【博客搬家】本博客已全面停止更新,新博客地址 plusplus7.com
新博客地址:http://www.plusplus7.com原创 2013-11-23 21:24:40 · 1414 阅读 · 0 评论