
数论
Egqawkq
北航CS研一在读
展开
-
hdu 1695 莫比乌斯反演
GCDProblem DescriptionGiven 5 integers:a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = k. GCD(x,y) means the greatest common divisor of x and y. Since the number of choic原创 2017-09-26 20:36:49 · 289 阅读 · 0 评论 -
HDU 6134(2017 多校训练:Battlestation Operational(莫比乌斯反演))
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6134这题就是求考虑当Gcd(i, j)==1时,除了j为1的情况,其它时候i/j一定是小数,所以i/j向上取整相当于向下取整的结果+1。这里注意的是,题目要求的是向上取整,这里转化成了向下取整(因为出现向下取整这种情况代表i和j互质,而欧拉函数就是求互质个数原创 2017-09-26 20:38:52 · 403 阅读 · 0 评论 -
codeforces 899D. Shovel Sale
#includeusing namespace std;typedef long long ll;int main(){ ll n;scanf("%lld",&n); if(n<5) { printf("%d\n",n*(n-1)/2); return 0; } ll i=5; while(i*10<=n)原创 2017-12-18 11:46:28 · 438 阅读 · 0 评论 -
wannafly挑战赛9 C.列一列
给你一个数,输出这个数在数列中处于第几的位置思路:类似哈希的那种思想,找一个大一点的质数,不停的mod,一般不会出现重复#include <bits/stdc++.h>using namespace std;const int N=1e5+7;const long long int mod=177777777;;long long int a[N];int main()...原创 2018-02-02 22:26:15 · 446 阅读 · 2 评论 -
codeforces 919E. Congruence Equation
/*题意:n*a^n≡b(mod p),其中1<=n<=x,求满足条件的n的个数思路:令n=i×(p−1)+j,因为根据费马小定理可以保证j有解,所以有 n*a^(i*(p-1)+j)≡b(mod p) n≡b*a^-1(mod p) i×(p−1)+j≡b*a^-1(mod p) j-i≡b*a^-1(mod p) 我们枚举j,此时j介于1与p-...原创 2018-02-11 18:27:10 · 371 阅读 · 0 评论 -
Codeforces 1154 G. Minimum Possible LCM (贪心+简单数论)
题目:给定数组A,找到下标I和J使得A[i]和A[j]的最小公倍数最小,数据范围是2<=n<=1e6,A[i]<=1e7思路:如果是按照正常做法求解GCD和LCM,那么是O(n^2)复杂度,题目要求是NlgN内求解,所以转换思路每次枚举GCD按照当前的GCD去选出满足条件的答案。需要注意的是对于同一个GCD:d而言,两个数均为d的倍数,那么这两个数最小即可,没有必要继续枚举下...原创 2019-04-24 23:12:44 · 340 阅读 · 0 评论 -
codeforces-886-E. Maximum Element(Технокубок 2018 - Отборочный Раунд 3)
E. Maximum Elementtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Petya was solving a very interesting problem. But a...原创 2017-11-13 22:58:32 · 1940 阅读 · 0 评论 -
UVAlive7040(组合数,容斥原理,逆元)
题意:给n朵花上色,从m种颜色里面选择恰好k种颜色,求总数MOD1e9+7思路:首先如果用k种颜色给花上色的话,肯定是k∗(k−1)n−1种方案,但是要求的是恰好k种,很容易想到用容斥原理解决这个问题。设Ai表示没选第i种颜色的种类数目,则结果为|A1¯¯¯¯∩A2¯¯¯¯∩...∩Ak¯¯¯¯|=k∗(k−1)n−1−∑|Ai|+∑|Ai∩Aj|+...+(−1)k∑|A1∩...转载 2017-10-09 21:52:41 · 356 阅读 · 0 评论