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> ...
随机推荐
- 【BZOJ 1146】[CTSC2008]网络管理Network
树剖+树状数组套线段树O(nlogn^3)(我打的),有一种更加优秀的算法是O(nlogn^2)的就是直接树状数组套线段树欧拉序(并不快),或者是用主席树维护原始的树的信息,同时用树状数组套线段树维护 ...
- 【NOIP模拟赛】藏宝图 最小生成树
性质:我们把最小生成树建出来,如果其距离符合那么就是对的,不符合就是错的 因为这是个n^2的图所以不能Kruskal只能Prim #include <cstdio> #include &l ...
- Hyperledger Fabric架构详解
区块链开源实现HYPERLEDGER FABRIC架构详解 区块链开源实现HYPERLEDGER FABRIC架构详解 2018年5月26日 陶辉 Comments 10 Comments hyper ...
- POJ1087:A Plug for UNIX(最大流)
A Plug for UNIX 题目链接:https://vjudge.net/problem/POJ-1087 Description: You are in charge of setting u ...
- region xx not deployed on any region server
ERROR: Region { meta => month_hotstatic,860010-2288000000_201405_5_exit_00000047486,1400144486405 ...
- Firefox多国语言多OS离线安装包
Download Firefox in your language Firefox is made in large part by volunteers around the world. That ...
- BigDecimal精度问题
介绍 1.商业计算使用BigDecimal. 2.使用参数为String的构造函数. 3.BigDecimal都是不可变的,每一步的运算时,都会产生一个新的对象.所以在做加减乘除后千万要保存操作后的值 ...
- [Leetcode Week1]Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/longes ...
- 【洛谷P1343】地震逃生
一道傻吊的网络流题,wori我写的读入优化怎么老T? 远离读入优化报平安? #include<bits/stdc++.h> #define N 4005 #define inf 10000 ...
- [ 手记 ] 关于tomcat开机启动设置问题
今天尝试将tomcat设置为开机启动,大家都知道只需要将启动脚本添加到/etc/rc.local下面开机就会自动执行. /usr/local/tomcat8./bin/startup.sh >& ...