数学--数论--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)+…+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) 暴力打表找规律的更多相关文章
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- 【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律
转自:http://www.cnblogs.com/kevince/p/3887827.html 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这么一说大家心里肯定有数了吧,“不就是nex ...
- HDU 1021 Fibonacci Again【打表找规律】
Fibonacci Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Just Random HDU - 4790 思维题(打表找规律)分段求解
Coach Pang and Uncle Yang both love numbers. Every morning they play a game with number together. In ...
- 数学--数论--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 ...
- bzoj1002 轮状病毒 暴力打标找规律/基尔霍夫矩阵+高斯消元
基本思路: 1.先观察规律,写写画画未果 2.写程序暴力打表找规律,找出规律 1-15的答案:1 5 16 45 121 320 841 2205 5776 151 ...
- hdu 4731 2013成都赛区网络赛 找规律
题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举
- hdu 2582 f(n) 数学
打表找规律: 当n为质数是,GCD(n)=n; 当n为质数k的q次方时,GCD(n)=k; 其他情况,GCD(n)=1. 代码如下: #include<iostream> #include ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
随机推荐
- java web数据库的增删改查详细
本次课上实验是完成数据库的增删改查. 包括增加用户信息.删除用户信息.多条件查找用户信息.修改用户信息(主要是复选框单选框等的相关操作.) 下面下看一下各个界面的样子. 总页面:显示全部页面:增加页面 ...
- django rest framework用户认证
django rest framework用户认证 进入rest framework的Apiview @classmethod def as_view(cls, **initkwargs): &quo ...
- Java第十六天,list接口
List接口 1.三大特点: ① 有序.② 有索引. ③ 允许存在重复元素. 注意: ① 利用list接口的索引执行操作时,要防止索引越界引起的程序错误. 2.基本使用: 针对List接口有索引的特点 ...
- django中写分页
1.引用函数import from django.core.paginator import Paginator 2.分页 page_obj = Paginator(Article.objects.a ...
- Vue-CLI 3.x 部署项目至生产服务器
本文已同步到专业技术网站 www.sufaith.com, 该网站专注于前后端开发技术与经验分享, 包含Web开发.Nodejs.Python.Linux.IT资讯等板块. 本教程主要讲解的是 Vue ...
- Linux CentOS7 开通端口外网端口访问权限
一.查看系统防火墙状态(如果返回 running 代表防火墙启动正常)firewall-cmd --state二.开启端口外网访问1.添加端口 返回 success 代表成功(--permanent永 ...
- jetCache 基本使用
1.pom引用 <!--jetcache缓存 lettuce--> <dependency> <groupId>com.alicp.jetcache</gro ...
- MYSQ创建联合索引,字段的先后顺序,对查询的影响分析
MYSQ创建联合索引,字段的先后顺序,对查询的影响分析 前言 最左匹配原则 为什么会有最左前缀呢? 联合索引的存储结构 联合索引字段的先后顺序 b+树可以存储的数据条数 总结 参考 MYSQ创建联合索 ...
- 利用 Github 网络钩子实现自动化部署
GitHub 的网络钩子(webhook)功能,可以很方便的实现自动化部署.本文记录了使用 Node.js 的开发部署过程,当项目的 master 分支被推时,将在服务器进行自动部署 添加网路钩子 在 ...
- 用threejs实现三维全景图
网络上看到了3D全景图,发现threejs里面有一个库竟然可以实现,一下我贴出代码: <!DOCTYPE html> <html> <head> <meta ...