zoukankan      html  css  js  c++  java
  • Codeforces 776E The Holmes Children

    题目链接:http://codeforces.com/problemset/problem/776/E


    ${ecause gcd(i,n-i)=1Leftrightarrow gcd(i,n)=1}$

    ${ herefore f(x)=phi (x)}$

    ${ecause sum_{d|x}phi(d)=x}$

    ${ herefore g(x)=x}$

    问题转换为求${phi(phi(phi(...)))}$嵌套${left lfloor frac{k}{2} ight floor}$层。

    考虑这样的嵌套至多${log}$次就会到$1$,所以直接暴力做就可以了。


     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<vector>
     5 #include<cstdlib>
     6 #include<cmath>
     7 #include<cstring>
     8 using namespace std;
     9 #define maxn 10010
    10 #define llg long long 
    11 #define md 1000000007
    12 #define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
    13 
    14 
    15 llg phi(llg x)
    16 {
    17     llg m=sqrt(x+0.5);
    18     llg ans=x;
    19     for (llg i=2;i<=m;i++)
    20         if (x%i==0)
    21         {
    22             ans=ans/i*(i-1);
    23             while (x%i==0) x/=i;
    24         }
    25     if (x>1) ans=ans/x*(x-1);
    26     return ans;
    27 }
    28 llg n,m,k;
    29 
    30 int main()
    31 {
    32     yyj("E");
    33     cin>>n>>k;
    34     llg ans=phi(n);
    35     for (llg i=2;i<=k;i++)
    36     {
    37         if (i%2) ans=phi(ans);
    38         if (ans==phi(ans)) break;
    39     }
    40     cout<<ans%md;
    41     return 0;
    42 }
    本文作者:xrdog 作者博客:http://www.cnblogs.com/Dragon-Light/ 转载请注明出处,侵权必究,保留最终解释权!
  • 相关阅读:
    centos 6.5 添加静态ip
    质数因子
    sizeof 和 strlen 的区别
    C++输入带空格的字符串
    字符集合
    汽水瓶
    算法汇总
    Word目录生成
    0-1背包问题的动态规划法与回溯法
    vue父元素调用子组件的方法报undefined
  • 原文地址:https://www.cnblogs.com/Dragon-Light/p/6437420.html
Copyright © 2011-2022 走看看