This time I need you to calculate the f(n) . (3<=n<=1000000)

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

题目就是这么短小精悍,这题我实在不知道怎么写,然后也不会数论的推理,我就打了表,发现跟质数的关系很大,就顺着推了一下, 就过了。

#include <iostream>
#include<cstdio>
#define ll long long
#define maxn 1000000
using namespace std;
int zs[maxn], t = 0, n;
ll f[maxn + 5];
bool v[maxn + 5]; int main()
{
for (int i = 2; i <= maxn; i++)
{
if (!v[i]) f[i] = zs[++t] = i;
for (int j = 1,u = zs[j] * i; j <= t && u<= maxn; j++)
{
v[u] = 1;
if (!(i % zs[j]))
{
f[u] = f[i];
break;
}
f[u] = 1;
u = zs[j+1] * i;
}
}
for (int i = 4; i <= maxn; i++)
f[i] += f[i - 1];
while (scanf("%d", &n)!=EOF)
printf("%lld\n", f[n]);
return 0;
}

数学--数论--HDU 2582 F(N) 暴力打表找规律的更多相关文章

  1. 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用

    转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html    ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...

  2. 【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律

    转自:http://www.cnblogs.com/kevince/p/3887827.html 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这么一说大家心里肯定有数了吧,“不就是nex ...

  3. HDU 1021 Fibonacci Again【打表找规律】

    Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. Just Random HDU - 4790 思维题(打表找规律)分段求解

    Coach Pang and Uncle Yang both love numbers. Every morning they play a game with number together. In ...

  5. 数学--数论--HDU 2802 F(N) 公式推导或矩阵快速幂

    Giving the N, can you tell me the answer of F(N)? Input Each test case contains a single integer N(1 ...

  6. bzoj1002 轮状病毒 暴力打标找规律/基尔霍夫矩阵+高斯消元

    基本思路: 1.先观察规律,写写画画未果 2.写程序暴力打表找规律,找出规律 1-15的答案:1    5    16    45    121 320 841     2205   5776 151 ...

  7. hdu 4731 2013成都赛区网络赛 找规律

    题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举

  8. hdu 2582 f(n) 数学

    打表找规律: 当n为质数是,GCD(n)=n; 当n为质数k的q次方时,GCD(n)=k; 其他情况,GCD(n)=1. 代码如下: #include<iostream> #include ...

  9. HDU 4861 Couple doubi (数论 or 打表找规律)

    Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...

随机推荐

  1. python 判断一个字符串是否是小数

    """练习判断一个小数1.判断是否合法2.合法需要有一个小数点3.小数点左边必须是个整数,右边必须是个正整数 """ def xiaoshu ...

  2. Django 配置访问顺序 ->MTV开发模式

    框架模式mvc m-->model 数据库 v-->view  视图 c-->controller  控件逻辑 mtv(django) m-->model 数据库 t--> ...

  3. sql 案例

    select now();#获取当前系统时间 select now() from dual;#与Oracle兼容 show character set;#产看当前数据库支持的字符集 create da ...

  4. 《闲扯Redis五》List数据类型底层之quicklist

    一.前言 Redis 提供了5种数据类型:String(字符串).Hash(哈希).List(列表).Set(集合).Zset(有序集合),理解每种数据类型的特点对于redis的开发和运维非常重要. ...

  5. 使用RNN对文本进行分类实践电影评论

    本教程在IMDB大型影评数据集 上训练一个循环神经网络进行情感分类. from __future__ import absolute_import, division, print_function, ...

  6. OAuth-授权机制

    一.应用场景 有一个"云冲印"的网站,可以将用户储存在Google的照片,冲印出来.用户为了使用该服务,必须让"云冲印"读取自己储存在Google上的照片. 问 ...

  7. 基于layui,Jquery 表格动态编辑 设置 编辑值为 int 或者 double 类型及默认值

    首先先推荐大家在看这篇笔记时,阅读过我写的这篇 Layui表格编辑[不依赖Layui的动态table加载] 阅读过上面那篇笔记之后呢,才能更好的理解我现在所要说的这个东西 接下来废话不多说,上代码. ...

  8. ASP.NET Core 与 ASPOSE.Words for .NET

    Aspose.Total是Aspose公司旗下的最全的一套office文档管理方案,它提供的原生API可以对Word.Excel.PDF.Powerpoint.Outlook.CAD.图片.3D.ZI ...

  9. Ubuntu中安装Hadoop

    安装前 1,更新apt sudo apt-get update   会让你输入密码(自己登录Ubuntu的时候设置的),输入密码不会显示在终端面板上,确定自己敲对之后点回车就行. 2,安装SSH服务器 ...

  10. scrapy爬虫实例(1)

    爬虫实例 对象 阳光问政平台 目标 : 主题,时间,内容 爬取思路 预先设置好items import scrapy class SuperspiderItem(scrapy.Item): title ...