
数学
acblacktea
永不放弃
展开
-
ahu 350 分解因式
数论知识略微加一点贪心思想,主要是学好数学啊。。。 把一个数(n<100000000)分解成质数相乘形式#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> int main() { int i,j,k,n,s,n1,i1; while(scanf("%d",&n)!=EOF) {原创 2015-07-29 14:39:09 · 610 阅读 · 0 评论 -
codeforces Educational Codeforces Round 16 D. Two Arithmetic Progressions 扩展欧几里得
先用exgcd等式求k的通解 然后根绝函数的单调性确定可选整数的区间注意点很多有点恶心 然后求个数就行了 坑点是整数运算两个数相除 a/b 的结果为正返回小于等于结果的第一个数,结果为负返回大于等于结果的第一个数 //1 9 3 11 49 109 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream>原创 2016-08-25 15:06:52 · 423 阅读 · 0 评论 -
poj 2480 Longge's problem 关于欧拉函数和积形函数推导
已知欧拉函数是积性函数 当 n = m1 * m2 m和m2互质 已知∑gcd(i, N) 1<=i <=N. 的值等于 ∑phi(n/i) * i 1 <= i <= n && n/i ==0 因为两个数a, b要使他们的公约数为i 那么必须有a%i=0且b%i=0 且a/i和b/i互质 所以求 n/i 的欧拉函数即为剩下的乘数可选个数因为欧拉函数是积性函数, 积性函数的和还是积性函数原创 2016-08-28 12:17:05 · 565 阅读 · 0 评论 -
hdoj 5071 中位数计数
思维题bzoj原题。。。 枚举每个点补充,把每个点的左前缀和右前缀的大于它减小于它的差的情况都搞出来就行了不超时。。。 为什么感觉百度之星第二场比第一场题更适合我然而。。。都是天意啊#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define MAXN 17005 #define MID 8100 u原创 2016-05-25 20:24:24 · 295 阅读 · 0 评论 -
hdu-5668- Circle 逆元+卡特兰数知识模板
(a/b)%mod = (a%mod*(b的逆元))%mod 逆元求法: //1: 通用扩展欧几里得; long long extend_gcd(long long a,long long b,long long &x,long long &y) { if(a==0&&b==0) return -1;//无最大公约数 if(b==0){x=1;y=0;retu原创 2016-05-16 23:41:10 · 654 阅读 · 0 评论 -
ahu-563-3次幂分解
(1)把n化成三进制; (2)x位为0不考虑; (3)x位为2考虑成3^(x+1)-3^x;为1考虑成3^x; ( 4 )还有一些细节消除多余项自己考虑。。。#include<cstdio> #include<queue> #include<stack> using namespace std; int n,t; long long thi[30]; int main() { sca原创 2016-04-07 22:40:29 · 433 阅读 · 0 评论 -
ahu-557容斥原理
用容斥求1-n中能被2-i中素数整除的个数ans其中 i*i<=n;然后结果为n-ans-1;#include<cstdio> int pri[10005],pri2[10005],i1,n,ans; void toGetPrim(){ for(int i=2;i<=10001;i++) if(!pri[i]){ for(int j=2;j*i<=10001;j++原创 2016-03-12 14:16:15 · 433 阅读 · 0 评论 -
hdoj-1796 容斥水题
第一发略坑#include<cstdio> #include<iostream> #include<algorithm> using namespace std; __int64 n,m,ans,sum,a[20],b; __int64 lcm(__int64 a,__int64 b) { int a1 = a,b1 = b; while(b){ long long原创 2016-03-11 22:11:50 · 283 阅读 · 0 评论 -
BestCoder Round #78 (div.1) CA Loves GCD
因子分解,然后把约数为1到1000的方案都求出来,比如约数为2的方案为2^(n个数中能被2整除的个数)-1,然后从1000到1逆推,推的过程要更更新小约数的值比如推完am[8]时,am[2],am[4],am[1]都要减去am[8](因为m个数的公约数为8时那公约数一定也为2和4,)逆推可以保证最大公约数。 这么水的题都要想很长时间我真是太渣了。。。#include<cstdio> #includ原创 2016-04-02 22:56:06 · 302 阅读 · 0 评论 -
poj-1833-排列 stl next_permutation(a,a+n)
#include<cstdio> #include<algorithm> using namespace std; int t,n,m; int a[2000]; int main() { scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=0;i<n;i++)原创 2016-04-01 23:08:01 · 413 阅读 · 0 评论 -
codeForces-Longest Subsequence
#include<cstdio> #include<cstring> using namespace std; int a[1100000],b[1100000],n,k, c[1100000]; int main() { while(scanf("%d%d",&n,&k)!=EOF) { memset(b,0,sizeof(b)); int i1 =原创 2016-03-15 21:04:09 · 329 阅读 · 0 评论 -
codeforces-A Trivial Problem 判断n!末尾0的个数模板
即判断n!有多少个5#include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<queue> #include<stack> #include<set> #include<vector> #include<ctime> using namespace std; i原创 2016-03-01 12:52:29 · 347 阅读 · 0 评论 -
扩展欧几里得模板 poj-C Looooops
poj撸了三个专题了虽然前几个很难但还可以自己想出来,到数论这都是坎,只能看题解慢慢学了。。。 总结下知识点 1 欧几里得定理 GCD(a,b) = GCD(b,a%b) 代码实现渣渣我都能毫不思考的打出来了。 2 ax+by = gcd(a,b)有解 同理可推出 ax+by=c有解的充要条件是c%gcd(a,b)=0; ax+by=gcd(a,b)通解为x = x0+b/gc原创 2015-11-22 22:36:25 · 532 阅读 · 0 评论 -
POJ 1845-Sumdiv 数论 +快速幂&&筛素&&分解质因数&&求因数之和的模板
poj计划的第一个坎,非常经典的一道题在此记录一下以后总结 知识点: 1 (a+b)%c = (a%c+b%c)%c (a*b)%c = ((a%c)*(b%c))%c2 计算a^n 要用快速幂((logn)渣渣我都能迅速打出来)3 任何数都能分解成几个质因数相乘4 求一个数的所有因数之和 = (a^0+a^1+a^2+a^3+….a^n) * ( a1^0+a1^1+a1^原创 2015-11-20 23:35:55 · 1257 阅读 · 2 评论 -
ahu - 572
组合数学水题~~~#include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <queue> #include <stack> #include <set> #include <map> #include <time.h>//-----------------------分割线呵呵--------原创 2015-09-20 09:48:27 · 297 阅读 · 0 评论 -
hdoj-GT and numbers
bc60我迄今为止最好的排名——98因为大牛都打区域赛了。。。 这题当时挂了 坑点 1 2的63 用unsigned long long 2 n是不断变化的! 思路 把n的质因数化出来并分别记录他们的数量; every个质因数计算 n必须乘他的质因数到m的次数求出来,注意n在不断变化质因数的数量在不断变化 具体次数=s (s取最大使质因数*2的s次方小于m原创 2015-10-18 23:25:19 · 364 阅读 · 0 评论 -
codeforces 711E 勒让德定理 逆元
要先化简再取模 公式很好推主要是化简 用到两条性质 1. gcd(2^n - k, 2^n) = gcd(k, 2 ^ n) 因为当k为奇数 2^n - k 为奇数 那等式两边都为1 当k为偶数时 2^n - k 为偶数 k = b * 2^k1 b为奇数 2^n - k = 2^k1*(2^(n-k1)-b) 2^(n-k1)-b 是奇数,所以gcd(2^n - k, 2^n) = gc原创 2016-09-06 22:37:45 · 652 阅读 · 0 评论