zoukankan      html  css  js  c++  java
  • BZOJ2705 [SDOI2012]Longge的问题

    2705: [SDOI2012]Longge的问题

    Time Limit: 3 Sec  Memory Limit: 128 MB
    Submit: 1654  Solved: 1042
    [Submit][Status][Discuss]

    Description

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

    Input

    一个整数,为N。

    Output

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

    Sample Input

    6

    Sample Output

    15

    HINT

    【数据范围】

    对于60%的数据,0<N<=2^16。

    对于100%的数据,0<N<=2^32。

     

    Source

    round1 day1

    【思路】源于网上

       白书不愧是神书,与UVa11426同

    【代码】

     1 #include<iostream>
     2 #include<cmath>
     3 using namespace std;
     4 
     5 typedef long long LL;
     6 int n;
     7 
     8 inline LL euler_phi(int p) {
     9     int m=sqrt(p);
    10     LL ans=p;
    11     for(int i=2;i<=m;i++) if(p%i==0)
    12     {
    13         ans=ans/i*(i-1);
    14         while(p%i==0) p/=i;
    15     }
    16     if(p>1) ans=ans/p*(p-1);
    17     return ans;
    18 }
    19 
    20 int main() {
    21     cin>>n;
    22     LL ans=0;
    23     for(int i=1;i*i<=n;i++)
    24      if(n%i==0) {
    25          ans += i*euler_phi(n/i);
    26          if(i*i<n) ans += n/i*euler_phi(i);
    27      }
    28      cout<<ans;
    29      return 0;
    30 }
  • 相关阅读:
    java基础之switch
    String的getBytes()方法
    Android adb命令
    shell中grep命令详解
    su root 和su
    adb shell 命令详解
    adb shell am 的用法
    adb logcat 基本用法
    Android、iOS和Windows Phone中的推送技术
    Android客户端消息推送原理简介
  • 原文地址:https://www.cnblogs.com/lidaxin/p/4883684.html
Copyright © 2011-2022 走看看