zoukankan      html  css  js  c++  java
  • UVA 11426 GCD

    G=0;
    for(i=1;i<N;i++)
    for(j=i+1;j<=N;j++)
    {
      G+=gcd(i,j);
    }
     
    SampleInput
    10
    100
    200000
    0
    SampleOutput
    67
    13015
    143295493160
    #include <algorithm>
    #include <iostream>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <map>
    using namespace std;
    typedef long long LL;
    const LL N = 4000000 + 10;
    const LL MOD = 1000;
    LL s[N], f[N], phi[N];
    void funp()
    {
        LL i, j;
        for(i = 2; i < N; i++)
            phi[i] = 0;
        phi[1] = 1;
        for(i = 2; i < N; i++)
            if(!phi[i]) {
                for(j = i; j < N; j += i) {
                    if(!phi[j])
                        phi[j] = j;
                    phi[j] = phi[j] / i * (i - 1);
                }
            }
    }
    LL init()
    {
        LL i, j;
        funp();
        for(i = 1; i < N; i++) {
            for(j = i + i; j < N; j += i)
                f[j] += i * phi[j / i];
        }
        s[2] = f[2];
        for(i = 3; i < N; i++)
            s[i] = s[i - 1] + f[i];
    }
    int main()
    {
        LL n;
        init();
        while(scanf("%lld", &n), n) {
            printf("%lld
    ", s[n]);
        }
        return 0;
    }
  • 相关阅读:
    vue 兼容IE报错解决方案
    JDK1.8 ArrayList 源码解析
    Mac nasm 汇编入门
    命令模式
    模板方法
    Mysql Limit 调优
    观察者模式
    外观模式
    Rest- Client
    MongoDB数据库 5分钟快速上手
  • 原文地址:https://www.cnblogs.com/yu0111/p/6759019.html
Copyright © 2011-2022 走看看