• 2705: [SDOI2012]Longge的问题


    Time Limit: 3 Sec  Memory Limit: 128 MB
    Submit: 4064  Solved: 2596
    [Submit][Status][Discuss]

    Description

    Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题。现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N)。

    Input

    一个整数,为N。

    Output

    一个整数,为所求的答案。

    Sample Input

    6

    Sample Output

    15

    HINT

     

    0<N<=2^32。

    2019.1.1新加数据一组。 

    欧拉函数

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 using namespace std;
     5 #define LL long long
     6 
     7 int eular(LL n)
     8 {
     9     LL ret=n;
    10     LL nn=sqrt(n);
    11     for(LL i=2;i<=nn;i++)
    12     {
    13         if(n%i==0)
    14             ret=ret/i*(i-1);
    15         while(n%i==0) n/=i;
    16     }
    17     if(n>1) ret=ret/n*(n-1);
    18     return ret;
    19 }
    20 
    21 LL n,ans;
    22 
    23 int main()
    24 {
    25     scanf("%lld",&n);
    26     LL nn=sqrt(n);
    27     for(LL i=1;i<=nn;i++)
    28     {
    29         if(n%i==0) ans+=i*eular(n/i)+(n/i)*eular(i);
    30     }
    31     if(nn*nn==n) ans-=eular(nn)*nn;
    32     printf("%lld",ans);
    33     return 0;
    34 }
  • 相关阅读:
    L1-046. 整除光棍
    L2-014. 列车调度
    L2-009. 抢红包
    L2-005. 集合相似度
    L2-021. 点赞狂魔
    L1-033. 出生年
    设计模式之生成器模式
    设计模式之抽象工厂模式
    设计模式之工厂方法模式
    设计模式之简单工厂模式
  • 原文地址:https://www.cnblogs.com/InWILL/p/10615077.html
Copyright © 2020-2023  润新知