zoukankan      html  css  js  c++  java
  • POJ-1284 Primitive Roots---原根&欧拉函数

    题目链接:

    https://cn.vjudge.net/problem/POJ-1284

    题目大意:

    就是给出一个奇素数,求出他的原根的个数。

    解题思路:

     

    由于是m是奇素数,m的欧拉函数值为m - 1,所以直接求出ϕ(m - 1)即可 

     1 #include<iostream>
     2 #include<cmath>
     3 using namespace std;
     4 typedef long long ll;
     5 int euler_phi(int n)//求单个
     6 {
     7     int m = (int)sqrt(n + 0.5);
     8     int ans = n;
     9     for(int i = 2; i <= m; i++)if(n % i == 0)
    10     {
    11         ans = ans / i * (i - 1);
    12         while(n % i == 0)n /= i;
    13     }
    14     if(n > 1)ans = ans / n * (n - 1);
    15     return ans;
    16 }
    17 int main()
    18 {
    19     int n;
    20     while(cin >> n)
    21     {
    22         cout<<euler_phi(n - 1)<<endl;
    23     }
    24     return 0;
    25 }
  • 相关阅读:
    HDU
    HDU
    HDU
    HDU
    HDU
    HDU
    HDU
    HDU
    HDU
    HDU
  • 原文地址:https://www.cnblogs.com/fzl194/p/9038430.html
Copyright © 2011-2022 走看看