
数论&&组合数学
taozifish
http://www.daimayu.com/
展开
-
输入一个数,1~2^24, 输出它的最大质因子和不同质因子的个数。
//输入一个数,1~2^24, 输出它的最大质因子和不同质因子的个数。//先打素数表,然后搞之。。#include#include#include#includeusing namespace std;const int MAX=16777217;原创 2011-08-02 13:41:03 · 1030 阅读 · 0 评论 -
poj 3021 A Number from Yanghui Triangle
推出公式来就是水题。S(n,k) = C(n,0)+10^k*C(n,1)+10^2k*C(n,2)+.... ...+10^nk*C(n,n) 10^k*S(n,k) = 10^k*C(n,0)+10^2k*C(n,1)+10^3k*C(n,2)+.... ...+10^(n+1)k*C(n,n)两式求和可得 S(n, k) + 10^k*S(n, k) = S(n+1, k)原创 2012-10-02 19:45:47 · 743 阅读 · 0 评论 -
hdu 4344 Mark the Rope
2^64内大整数分解质因子,比之前的模版快#include #include #include #include #include using namespace std;typedef long long LL;using namespace std;const int prime[]={0,2,3,5,7,11,13,17,19,23};LL gcd(LL x, LL原创 2012-08-09 20:51:30 · 680 阅读 · 0 评论 -
hdu 4355 Party All the Time
//模版题,三分法#include #include #include #include #include using namespace std;const double EPS=1e-8;struct node{ double x, w;}p[50005];int n;double Calc(double t){ double ret=0; for(原创 2012-08-09 20:47:12 · 401 阅读 · 0 评论 -
母函数初级运用 hdu 1028 、hdu 1398、hdu 1085
母函数即生成函数,有普通型生成函数和指数型生成函数两种,常用于组合数学中求某个问题的方法数。例:G(x) = a0 + a1x + a2x*2 + a3x^3 +....+ anx^n其中ai表示i的组合数。 例题1:hdu 1028 Ignatius and the Princess III题目描述:输入正整数n(n//输入正整数n(n<=120),输出由正整数组成的和为原创 2012-05-03 21:08:34 · 462 阅读 · 0 评论 -
poj 2429 GCD & LCM Inverse
题意:给出两数的gcd和lcm,求乘积最小的两数。解法:枚举lcm/gcd的因子,套模版。 #include#include#include#include#include#define time 12using namespace std;int p2[20];const int C=200;const long long max1 = (long long)pow原创 2012-08-06 15:15:26 · 526 阅读 · 0 评论 -
poj 1811 Prime Test
题意:大整数判断素数,非素则求最小质因子。Pollard-Rho和Miller-Rabin各种纠结,自己的模版各种TLE,只好去copy别人的。Orz#include#include#include#include#include#define time 12using namespace std;const long long max1 = (long long)pow(原创 2012-08-06 12:02:20 · 395 阅读 · 0 评论 -
poj 2917 Diophantus of Alexandria
题意:1/x+1/y=1/n 给出n,求x、y的解数,x、y、n均为正整数。解法:1/x+1/y=1/n --> nx+ny=xy --> (n-x)*(n-y)=n*n 转化为求n*n小等于n的因子的个数,由于n达到10^9,直接求太大。将n分解质因子,复杂度为logn,n*n对应的质因子和n相同,且个数翻倍,即可得到n*n的质因子个数。 #include#includ原创 2012-07-20 16:04:42 · 616 阅读 · 0 评论 -
poj 2689 Prime Distance 小范围素数筛
题意:给你一个范围L到U,(1//小范围素数筛[s, t].#include#include#include#includeusing namespace std;const int INF=0x7fffffff;const int maxn=50005;bool isprime[maxn], isprime2[maxn*20];int prime[maxn], sum, s原创 2012-05-10 13:18:10 · 573 阅读 · 0 评论 -
poj 1701 Dissatisfying Lift
//自己推公式推了一个多小时,代码写了10分钟。。//设停在t层的不满意度为ans[t],推公式可以发现//ans[t+1]-ans[t]=b*(k1+k2+......+kt)-a*(kt+1 +kt+2....+kn)+kt-1+2*kt-2+......+(t-1)*k1 -kt+2-2*kt+3-......-(n-t-1)kn// 令dp[t]=ans[t+1]-an原创 2012-03-18 11:34:03 · 718 阅读 · 0 评论 -
hdu 2138 How many prime numbers (随即素数测试模版)
//题意:输入N个数,输出素数的个数。 #include#include#include#include#includeusing namespace std;long long bigpow(long long x,long long n, long long M){ long long res=1,temp=x%M; while(n){原创 2011-10-26 15:32:36 · 406 阅读 · 0 评论 -
poj 3071 Football
//概率题 //找出递推公式,dp[i][j]表示第i轮j生存下来的概率#include#include#includeusing namespace std;double dp[8][130], a[130][130];int n, p2[8];int main(){ //freopen("1.txt", "r", stdin); int i,原创 2011-10-20 13:01:37 · 479 阅读 · 0 评论 -
poj 2635 The Embarrassed Cryptographer
//大数取模//题意 输入大数K 和小数L, 判断是否存在小于L的质数能整除K//先写了1000进制的发现比较慢,然后改成10^11进制,快了许多 #include#include#include#includeusing namespace std;原创 2011-08-25 13:20:45 · 387 阅读 · 0 评论 -
Poj 2756 Autumn is a Genius
//题意:输入两个大整数,都可带正负号,输出他们的和。//大数的加减运算,带+、-号的细节处理 #include#include#include#include#include#include#includeusing namespace st原创 2011-08-24 19:00:30 · 557 阅读 · 0 评论 -
poj 1082 / hdu 1079 Calendar Game
题意:从一个日期开始,轮流改变时间,可以变为下一天或者是同一年的下一个月的当天。先到2001年11月4日的获胜。基础博弈问题任意能到达必败状态的位置为必胜状态,倒着递推一下。 #include#include#include#include#include#includeusing namespace std;int dp[120][15][35];struct n原创 2012-10-05 15:36:50 · 665 阅读 · 0 评论