zoukankan      html  css  js  c++  java
  • CF284A Cows and Primitive Roots

    嘟嘟嘟

    这道题就是求一个奇素数(p)的原根数量。   

    公式是(varphi(varphi(p)))。又因为(p)是质数,所以就是(varphi(p - 1))
    (证明啥的我不会……)

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<vector>
    #include<stack>
    #include<queue>
    using namespace std;
    #define enter puts("") 
    #define space putchar(' ')
    #define Mem(a, x) memset(a, x, sizeof(a))
    #define rg register
    typedef long long ll;
    typedef double db;
    const int INF = 0x3f3f3f3f;
    const db eps = 1e-8;
    //const int maxn = ;
    inline ll read()
    {
      ll ans = 0;
      char ch = getchar(), last = ' ';
      while(!isdigit(ch)) last = ch, ch = getchar();
      while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
      if(last == '-') ans = -ans;
      return ans;
    }
    inline void write(ll x)
    {
      if(x < 0) x = -x, putchar('-');
      if(x >= 10) write(x / 10);
      putchar(x % 10 + '0');
    }
    
    int n;
    int phi(int n)
    {
      int ans = n;
      for(int i = 2; i * i <= n; ++i)
        if(n % i == 0)
          {
    	ans = ans / i * (i - 1);
    	while(n % i == 0) n /= i;
          }
      if(n > 1) ans = ans / n * (n - 1);
      return ans;
    }
    
    int main()
    {
      while(scanf("%d", &n) != EOF) write(phi(n - 1)), enter;
      return 0;
    }
    
  • 相关阅读:
    es操作
    MySQL逻辑架构
    ceshimd
    mysql资料
    已解决 : VMware Workstation 与 Hyper-V 不兼容。请先从系统中移除 Hyper-V 角色
    MySQL数据库操作
    phpstorm配置laravel语法提示
    MySQL日志之慢查询日志(slow-log)
    456
    topcoder srm 553
  • 原文地址:https://www.cnblogs.com/mrclr/p/9970466.html
Copyright © 2011-2022 走看看