zoukankan      html  css  js  c++  java
  • 【Foreign】Uria [欧拉函数]

    Uria

    Time Limit: 20 Sec  Memory Limit: 512 MB

    Description

      从前有个正整数 n。

      对于一个正整数对 (a,b),如果满足 a + b ≤ n 且 a + b 是 a * b 的因子,则成为神奇的数对。

      求神奇的数对的个数。

    Input

      一行一个正整数 n。

    Output

      一行一个整数表示答案,保证不会超过 64 位有符号整数类型的范围。

    Sample Input

      21

    Sample Output

      11

    HINT

      n ≤ 1e14

    Solution

      

    Code

     1 #include<iostream>    
     2 #include<string>    
     3 #include<algorithm>    
     4 #include<cstdio>    
     5 #include<cstring>    
     6 #include<cstdlib>
     7 #include<cmath>
     8 using namespace std;  
     9 typedef long long s64;
    10 typedef unsigned int u32;
    11  
    12 const int ONE = 1e7 + 5;
    13 const u32 MOD = 20000116;
    14 
    15 s64 n, Q;
    16 s64 Ans;
    17 bool isp[ONE];
    18 s64 phi[ONE], prime[ONE], p_num;
    19 
    20 int get()
    21 {    
    22         int res=1,Q=1;char c;    
    23         while( (c=getchar())<48 || c>57 ) 
    24         if(c=='-')Q=-1; 
    25         res=c-48;     
    26         while( (c=getchar())>=48 && c<=57 )    
    27         res=res*10+c-48;
    28         return res*Q;
    29 }
    30 
    31 void Get_phi(int MaxN)
    32 {
    33         phi[1] = 1;
    34         for(int i = 2; i <= MaxN; i++)
    35         {
    36             if(!isp[i])
    37                 prime[++p_num] = i, phi[i] = i - 1;
    38             for(int j = 1; j <= p_num && i * prime[j] <= MaxN; j++)
    39             {
    40                 isp[i * prime[j]] = 1;
    41                 if(i % prime[j] == 0)
    42                 {
    43                     phi[i * prime[j]] = phi[i] * prime[j];
    44                     break;
    45                 }
    46                 phi[i * prime[j]] = phi[i] * phi[prime[j]];
    47             }
    48         }
    49 }
    50 
    51 int main()
    52 {
    53         cin>>n;    Q = sqrt(n);    
    54         Get_phi(Q);
    55         for(int i = 2; i <= Q; i++)
    56             Ans += (n / i / i) * phi[i];
    57         printf("%lld", Ans); 
    58 }
    View Code
  • 相关阅读:
    计数排序
    epel
    Web开发:我希望得到的编程学习路线图
    第五章:if语句与运算符
    java web学习建议
    第四章:c++数据类型
    第二章:做一个最简单的c++程序
    linux的商业应用
    第三章:初步了解函数
    解析Linux商业应用现状
  • 原文地址:https://www.cnblogs.com/BearChild/p/7617759.html
Copyright © 2011-2022 走看看