HDOJ 2582 f(n)
f(n)= Gcd(3)+Gcd(4)+…+Gcd(i)+…+Gcd(n).
Gcd(n)=gcd(C[n][1],C[n][2],……,C[n][n-1])
C[n][k] means the number of way to choose k things from n some things.
gcd(a,b) means the greatest common divisor of a and b.
Input
There are several test case. For each test case:One integer n(3<=n<=1000000). The end of the in put file is EOF.
Output
For each test case:
The output consists of one line with one integer f(n).
Sample Input
3
26983
Sample Output
3
37556486 本来毫无思路,然而打了个表找了找规律,发现Gcd(x)无非两种情况:
1.当x=p^q时,其中p为质数,那么Gcd(x)=p
2.其他的时候Gcd(x)=1 然后就是个水题了
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000000
using namespace std;
int zs[maxn/],t=,n;
ll f[maxn+];
bool v[maxn+]; inline void init(){
for(int i=;i<=maxn;i++){
if(!v[i]) f[i]=i,zs[++t]=i;
for(int j=,u;j<=t&&(u=zs[j]*i)<=maxn;j++){
v[u]=;
if(!(i%zs[j])){
f[u]=f[i];
break;
}
f[u]=;
}
} for(int i=;i<=maxn;i++) f[i]+=f[i-];
} int main(){
init();
while(scanf("%d",&n)==) printf("%lld\n",f[n]);
return ;
}
HDOJ 2582 f(n)的更多相关文章
- HDOJ 4734 F(x)
数位DP.... F(x) Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 2582 f(n) 数学
打表找规律: 当n为质数是,GCD(n)=n; 当n为质数k的q次方时,GCD(n)=k; 其他情况,GCD(n)=1. 代码如下: #include<iostream> #include ...
- hdoj 2802 F(N)【递推 规律】
F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDOJ 2802 F(N)
Problem Description Giving the N, can you tell me the answer of F(N)? Input Each test case contains ...
- 数学--数论--HDU 2582 F(N) 暴力打表找规律
This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gc ...
- Mysql_以案例为基准之查询
查询数据操作
- f(n) hdu 2582
calculate the f(n) . (3<=n<=1000000)f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gcd(n).Gcd(n)=gcd(C[n][1],C ...
- HDOJ 4389 X mod f(x)
数位DP........ X mod f(x) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- 【HDOJ】2802 F(N)
找循环节水题.注意余数大于0. /* 2802 */ #include <cstdio> #include <cstring> #include <cstdlib> ...
随机推荐
- HDU 1556 线段树/树状数组/区间更新姿势 三种方法处理
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- js中连写两个?:三元运算符语法解释
在angular 源码中有连写两个三元运算符的代码: var hash = isString(hash) ? hash : isNumber(hash) ? hash.toString() :$loc ...
- 计算1-1/x+1/x*x
// algo1-1.cpp 计算1-1/x+1/x*x. #include<stdio.h> #include<sys/timeb.h> void main() { time ...
- jzoj2701 【GDKOI2012模拟02.01】矩阵
传送门:https://jzoj.net/senior/#main/show/2701 [题目大意] 给出矩阵A,求矩阵B,使得
- hdu 2817 A sequence of numbers(快速幂取余)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2817 题目大意:给出三个数,来判断是等差还是等比数列,再输入一个n,来计算第n个数的值. #inclu ...
- echarts 图表建立步骤
需要引用的文件 <script src="web/mobile/js/jquery-1.8.3.min.js"></script> <script s ...
- 子类构造函数 supper关键字
在导出类的构造函数,如果没有明确指定调用哪一个基类构造器,它会默默调用默认构造器. 如果不存在默认构造器,编译器就会报错. java编程思想 p158(p194)
- tcpdump学习(2):基本使用
安装好tcpdump之后,运行tcpdump: 1. tcpdump -D 获取网络适配器列表,以下是在Ubuntu上获取到的结果: root@holmesian-laptop:~# tcpdump ...
- 前端工程师必备PS技能
PS参考线及其辅助 视图-->新建参考线 也可以快捷键Ctrl+R,显示区的上侧和左侧就会出现标尺.任意点选中,并拖动标尺,便会出现浅蓝色的辅助线.只有在移动工具下,才能拖动某一条参考线. 删除 ...
- hdu 5185(动态规划)
Equation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...