数论
skymeteorite
这个作者很懒,什么都没留下…
展开
-
n!素因子分解
题目#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std;const int maxn = 1e6+10;typedef long long LL;int p[maxn],cnt; bool prime[maxn]; int fac[1000],tot; in原创 2015-08-02 11:04:37 · 862 阅读 · 0 评论 -
hdu4135欧拉,容斥
http://acm.hdu.edu.cn/showproblem.php?pid=4135题意:求[A,B]中与n互素的个数。—-来自芷水的文章 转化一下思路: 1. 求[A,B]中的等于[1,B]中与互素的个数减[1,A-1]中与n互素的个数, 这就转化为[1,K]了。 2. 求[1,K]中与N互素的个数又转化为 K 减去 [1,K]中与N满足gcd(N,k1)>1的个数。原创 2015-10-31 21:10:35 · 376 阅读 · 0 评论 -
欧拉函数小结
欧拉函数:小于等于n的与n互质的数。 求法:因为任何数都可以表示成n = p1^a1*p2^a2*·····pi^ai 可以推出eular(n)=n*(1-1/p1)*(1-1/p2)········(1-1/pi); 因为对于每一个质因子,比如2,那么在小于n的数中,与n不互质的,与其公约数是2的倍数的占其1/2,所以乘上1/2就是剩下与n公约数不含2的,然后依次类推,对于每个n的约数,乘上原创 2015-10-29 17:39:09 · 622 阅读 · 0 评论 -
hdu2685gcd性质
Problem Description To think of a beautiful problem description is so hard for me that let’s just drop them off. :) Given four integers a,m,n,k,and S = gcd(a^m-1,a^n-1)%k,calculate the S.Input The f原创 2015-09-21 20:20:55 · 511 阅读 · 0 评论 -
素数定理
素数定理:小于n的素数的个数为 则 即n/ln n. http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=117这里n=10^n,代入化简。#include <iostream> #include <cmath> using namespace std;int main() {int n; while(cin>>n)原创 2015-09-21 19:57:15 · 399 阅读 · 0 评论 -
hdu1695欧拉,容斥
http://acm.hdu.edu.cn/showproblem.php?pid=1695区间x属于[1,b],y属于[1,d],问有多少对x,y满足gcd(x,y)=k [1,3] [3,1]是同一种情况。 转化一下gcd[1,a],[1,b]=k –>gcd[1,a/k][1,b/k]=1,即两区间内互素的个数。设a总为小的,b总为大的。 sum=sum1+sum2 sum1是1到a的原创 2015-11-03 16:55:45 · 293 阅读 · 0 评论 -
组合数的奇偶性
gggghvmf#include <iostream> #include <stdio.h> #include <cmath> using namespace std;int main() {int a[200][200]; int inp[200][200]; int t; while(cin>>t) { for(int i=0;i<t;i++) {原创 2015-06-27 17:52:11 · 609 阅读 · 0 评论 -
数根
题目(http://acm.hdu.edu.cn/showproblem.php?pid=1013) 一开始不知道计算数根的公式,直接做也能过,数据很大要用字符串#include <iostream> #include <string.h> using namespace std; char n[1000000]; int main() {while(cin>>n) { if(n[0]原创 2015-08-05 17:38:27 · 470 阅读 · 0 评论 -
hdu1299素因子分解
题意: 求方程1/x+1/y=1/n的解的个数 1/3+1/2 与1/2+1/3看作是一组解。 分析: 1/x+1/y = 1/n 设y = n + k; ==>1/x + 1/(n+k)=1/n; ==>x = n^2/k + n; 因为x为整数,k就是n^2的约数。然后对其素因子分解就可以了。#include <iostream> #include <cstrin原创 2015-08-02 09:46:31 · 379 阅读 · 0 评论 -
素因子分解
Description 假设x是一个正整数,它的值不超过65535(即1#include <iostream> #include <string.h> #include <algorithm> using namespace std; typedef long long LL; const int maxn=1e7; bool prime[maxn]; int fac[10000],p[maxn/原创 2015-08-02 09:22:50 · 526 阅读 · 0 评论 -
n!素因子分解2
有的时候我们需要对n!进行素因子分解,如果我们对1~n的每一个数都进行素因子分解然后再进行合并的话那么显然是很慢的因此我们需要重新来考虑这个问题。 我们对n!进行素因子分解: n! = 1*2*3*4*…*n,因此它一定含有小于等于n 的所有素数我们要对这些素数分别进行处理求出含有多少项。 例如我们求n!含有多少个素因子p 设f[n][p] 表示n!含有多少素因子p; 1*2*3*4*…n原创 2015-08-02 11:09:56 · 586 阅读 · 0 评论 -
hdu1796容斥
http://acm.hdu.edu.cn/showproblem.php?pid=1796求n能被m个数中任意数整除的个数; 就是n能被一个数整除的个数减去能被两个数整除的个数(即两个数的最小公倍数)加上能被三个数同时整除的个数……#include <iostream> #include <cstdio> using namespace std;typedef long long LL;int原创 2015-11-23 20:34:43 · 346 阅读 · 0 评论