
数论
threeh20
暑假有半个月整个人像死了一样,所以更加明白生命的可贵
展开
-
poj 1248 Primitive Roots
求一个素数不同的原根 就等于φ(φ(n))#include<iostream>#include<cstring>#include<cstdio>using namespace std;int main(){ int n; while(cin>>n) { int a=n-1; int ans=a; for(in...原创 2018-03-01 18:41:27 · 142 阅读 · 0 评论 -
2018 Multi-University Training Contest 7 hdu 6390 GuGuFishtion(莫比乌斯+欧拉函数)
http://acm.hdu.edu.cn/showproblem.php?pid=6390 对于一对 a b Gab=gcd/phi(gcd) 然后就是枚举gcd了。然后就是要解决如何快速求得1-n与1-m中gcd=i的对数,然后就是莫比乌斯了然后就超时了。。。。。。 代码是标程 学习一下。。。#include<bits/stdc++.h&g...原创 2018-08-14 14:12:54 · 195 阅读 · 0 评论 -
uva 10214 Trees in a Wood.
与poj 3090相似,只不过数据大了点,于是就预处理2000以内的数的φ,再结合poj 2773中用到的定理即可。#include <cstdio>#include <cmath>#include <map>using namespace std;typedef long long ll;ll p,b,n;void exgcd(ll c,ll d...原创 2018-03-01 18:46:42 · 213 阅读 · 0 评论 -
po2417 Discrete Logging
给出b n p 求l使得,b^l==n (mod p)学习了一下 BSGS算法。#include <cstdio>#include <cmath>#include <map>using namespace std;typedef long long ll;ll p,b,n;void exgcd(ll c,ll d,ll &x,ll &...原创 2018-03-01 18:46:06 · 190 阅读 · 0 评论 -
51nod 1135 原根
找一个质数p的最小原根就是找到一个最小的a使得a^(p-1)%p=1 ,找出p-1的所有质因数再结合快速幂即可。#include <stdio.h>#include <algorithm>#include <cmath>#include <iostream>#include <string.h>#include <cstr...原创 2018-03-01 18:45:34 · 146 阅读 · 0 评论 -
hdu 3579 Hello Kiki
同 poj 2891 那道题 也是除数不一定互质的中国剩余定理,但有细节问题,所以做的时候wa了十几发。。#include<stdio.h>#define LL __int64void exgcd(LL a,LL b,LL& d,LL& x,LL& y){ if(!b){d=a;x=1;y=0;} else { e...原创 2018-03-01 18:45:05 · 194 阅读 · 0 评论 -
poj 2115 C Looooops
同青蛙那道题类似,不过是化简式子的方法不一样,难度就在于化简。欧几里得扩展。#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>using namespace std;long long int ex(long long int a,long long in...原创 2018-03-01 18:44:35 · 120 阅读 · 0 评论 -
poj 2891 Strange Way to Express Integers
这道题就是解模线性方程组,因为除数都不互质,所以不能用中国剩余定理的方法。#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>using namespace std;long long int ex(long long int a,long long int...原创 2018-03-01 18:44:05 · 142 阅读 · 0 评论 -
poj 1061 青蛙的约会
这道题是比较经典的欧几里得扩展的题目。通过从题目的意思得到一个等式,再通过一些操作,使之化成ax+by=tgcd(a+b)的式子,求出x再乘上t即可。因为ax+by=gcd 是必有解的。#include<iostream>#include<cstring>#include<cstdio>using namespace std;long long int ...原创 2018-03-01 18:43:38 · 127 阅读 · 0 评论 -
poj 3090 Visible Lattice Points
在第一象限中,从原点看,能够看到多少个点,只有在整数坐标上有点。看图可以得出,只有2个坐标互质,才能被看到,如果不互质,即gcd!=1,则一定会被挡住。#include<iostream>#include<cstring>#include<cstdio>using namespace std;bool vis[1111][1111]; int an...原创 2018-03-01 18:43:13 · 191 阅读 · 0 评论 -
poj 2478 Farey Sequence
求n以内中所有互质对数的个数需要用类似于埃筛的方法来找n个数每个数比自己小且互质数的个数 #include<iostream>#include<cstring>#include<cstdio>using namespace std;long long int ans[1000002];int main(){ memset(ans,0,sizeof(...原创 2018-03-01 18:42:43 · 159 阅读 · 0 评论 -
poj 2773 Happy 2006
求自然数中第k个与n互质的数可以借助规律:如果ab互质,则a+t*b与b也互质,因此可得在1-(b-1)中的互质数的个数与t-(t+b-2)中的互质数的个数相同且一一对应 #include<iostream>#include<cstdio>#include<algorithm>using namespace std;long long int gcd(l...原创 2018-03-01 18:42:12 · 127 阅读 · 0 评论 -
2018 Multi-University Training Contest 8 hdu 6397 Character Encoding
http://acm.hdu.edu.cn/showproblem.php?pid=6397 队友瞎推的一个组合数。具体看代码吧。。预处理一下阶乘逆元。。 #include<iostream>#include<algorithm>#include<cstring>#include<vector>#include<...原创 2018-08-16 15:14:05 · 140 阅读 · 0 评论