Lightoj1007【欧拉函数-素数表】】的更多相关文章

基础题. PS:注意unsigned long long; 以及%llu #include<bits/stdc++.h> using namespace std; typedef unsigned long long ULL; typedef long long LL; const int N=5e6+10; bool isprime[N]; ULL res[N]; void init() { res[1]=1ULL; for(LL i=1;i<=5000000;i++) { ispri…
Bi-shoe and Phi-shoe Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach for his success. He needs some bamboos for his students, so he asked his assistant Bi-Shoe to go to the market and buy them.…
上三角行恰好是[1,n-1]的欧拉函数 http://www.luogu.org/problem/show?pid=2158#sub //#pragma comment(linker, "/STACK:167772160") #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <queue> #include…
The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b) = 1 arranged in increasing order. The first few are F2 = {1/2} F3 = {1/3, 1/2, 2/3} F4 = {1/4, 1/3, 1/2, 2/3, 3…
题意: 给一个数 N ,求 N 范围内所有任意两个数的最大公约数的和. 思路: f 数组存的是第 n 项的 1~n-1 与 n 的gcd的和,sum数组存的是 f 数组的前缀和. sum[n]=f[1]+f[2]+f[3]+-+f[n] sum[n-1]=f[1]+f[2]+-+f[n-1] sum[n]=sum[n-1]+f[n] 所以我们求出f[n]的值即可 1~n-1与 n 的最大公约数暴力来求肯定超时: 设gcd(x,n)=i 表示 n 和 x 的最大公约数为i,那么gcd( x/i ,…
/* * POJ_2407.cpp * * Created on: 2013年11月19日 * Author: Administrator */ #include <iostream> #include <cstdio> #include <cstring> using namespace std; typedef long long ll; const int maxn = 1000015; bool u[maxn]; ll su[maxn]; ll num; ll…
pid=3970">链接 题解:www.cygmasot.com/index.php/2015/08/17/hdu_3970 给定n  求连续整数[0,n), 中随意选一些数使得选出的数和为n的倍数的方法数 ...并不会怎样递推. . 思路: 然后这是公式:q=2%2C2%2C4%2C4%2C8%2C12%2C20%2C32%2C60&language=english&go=Search">点击打开链接 a(n) = 1/n * sum_{d divides…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9046    Accepted Submission(s): 3351 Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y…
转自:http://blog.csdn.net/dream_you_to_life/article/details/43883367 作者:Sky丶Memory 1.一个数是否为质数的判定. 质数,只有1和其本身才是其约数,所以我们判定一个数是否为质数,只需要判定2~(N - 1)中是否存在其约数即可,此种方法的时间复杂度为O(N),随着N的增加,效率依然很慢.这里有个O()的方法:对于一个合数,其必用一个约数(除1外)小于等于其平方根(可用反证法证明),所以我们只需要判断2-之间的数即可. b…
题目: The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 166 Accepted Submission(s): 96   Problem Description The Euler function phi is an important kind of function in number theory…