首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >数学--数论--HDU 2582 F(N) 暴力打表找规律

数学--数论--HDU 2582 F(N) 暴力打表找规律

作者头像
风骨散人Chiam
发布2020-11-06 00:17:45
发布2020-11-06 00:17:45
6980
举报
文章被收录于专栏:CSDN旧文CSDN旧文

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

代码语言:javascript
复制
#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;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/12/19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档