zoukankan      html  css  js  c++  java
  • BZOJ-1968

      

    1968: [Ahoi2005]COMMON 约数研究

    Time Limit: 1 Sec  Memory Limit: 64 MB
    Submit: 2308  Solved: 1768
    [Submit][Status][Discuss]

    Description

    Input

    只有一行一个整数 N(0 < N < 1000000)。

    Output

    只有一行输出,为整数M,即f(1)到f(N)的累加和。

    Sample Input

    3

    Sample Output

    5

    HINT

     

    Source

    /*
     * Author: lyucheng
     * Created Time:  2017年05月14日 星期日 16时13分57秒
     * File Name: /media/lyucheng/Work/ACM源代码/数学--数论/递推找规律打表/BZOJ-1968.cpp
     */
    /* 题意:定义了一种运算f(n)为n的因子个数,然后让你求1-n的f(n)的和
     *
     * 思路:进行离线打表
     *
     * 错误:考虑的太浅了,正常打标跑了2000ms+,应该反过来想,打欧拉函数线性筛欧拉函数,然后减去就行了
     *
     * 还是错误:上面的想法不对,这样筛输出来的只是和n不互质的数,但并不是因子
     *      换个思路不用于处理,n/i表示比n小的数中i的倍数有多少,这样O(n)就可以处理出来
     * */
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <set>
    #include <time.h>
    #define MAXN 1000005
    #define LL long long
    using namespace std;
    int n;
    int main(int argc, char* argv[])
    {
         //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout;
        while(scanf("%d",&n)!=EOF){ 
            LL res=0;
            for(int i=1;i<=n;i++){
                res+=n/i;
            }
            printf("%lld
    ",res);
        }
        return 0;
    }
  • 相关阅读:
    Live2D 看板娘
    Live2D 看板娘
    Live2D 看板娘
    [转载]jquery版结婚电子请帖
    [转载]jquery版小型婚礼(可动态添加祝福语)
    maven向本地仓库导入jar包(处理官网没有的jar包)
    Maven的POM.xml配置大全
    Linux使用手册-时区和时间设置
    Fedora中允许mysql远程访问的几种方式
    [Keygen]IntelliJ IDEA 14.1.7
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/6853027.html
Copyright © 2011-2022 走看看