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> ...
随机推荐
- [学习笔记]Tarjan&&欧拉回路
本篇并不适合初学者阅读. SCC: 1.Tarjan缩点:x回溯前,dfn[x]==low[x]则缩点. 注意: ①sta,in[]标记. ②缩点之后连边可能有重边. 2.应用: SCC应用范围还是很 ...
- [洛谷P2016] 战略游戏 (树形dp)
战略游戏 题目描述 Bob喜欢玩电脑游戏,特别是战略游戏.但是他经常无法找到快速玩过游戏的办法.现在他有个问题. 他要建立一个古城堡,城堡中的路形成一棵树.他要在这棵树的结点上放置最少数目的士兵,使得 ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends
C. Masha and two friends 题目链接:https://codeforc.es/contest/1080/problem/C 题意: 给出一个黑白相间的n*m的矩阵,现在先对一个子 ...
- BZOJ 4206: 最大团
4206: 最大团 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 91 Solved: 36[Submit][Status][Discuss] De ...
- 【20160811】noip模拟-未完
T1 T2 T3 小奇回地球 [问题描述] 简单来说,它要从标号为1的星球到标号为n的星球,某一些星球之间有航线.由于超时空隧道的存在,从一个星球到另一个星球时间可能会倒流,而且,从星球a到b耗费的时 ...
- 【Foreign】远行 [LCT]
远行 Time Limit: 20 Sec Memory Limit: 256 MB Description Input Output Sample Input 0 5 10 1 4 5 2 3 2 ...
- Chocolatey 使用
最近空了下来不干点什么就感觉脑袋热,可是出过的问题挖过的坑还是要自己去解决. 一直网络不好安装choco一直都是报错,今天又建立了chocolatey 在windows上来用,网络问题解决了,类似于m ...
- Kali 1.0 / 2.0 安装中文输入法(谷歌pinyin + 其他)
1.kali默认是没有中午输入法的,需要自己安装一下 2.首先我们先获取root权限 dnt@HackerKali:~$ su密码: 3.安装中文输入法(apt-get 指令不会的同学可以学习一下基础 ...
- UpdateData的用法(转)
原文转自 https://blog.csdn.net/ddjj_1980/article/details/51452289 UpdateData(TRUE)——刷新控件的值到对应的变量.(外部输入值交 ...
- concurrent
from concurrent.futures import ThreadPoolExecutor