zoukankan      html  css  js  c++  java
  • tyvjP1346 MMT数

    tyvjP1346 MMT数

    描述

    FF博士最近在研究MMT数(莫明堂数-_-)。
    如果对于一个数n,存在gcd(n,x)<>1并且n mod x<>0 那么x叫做n的MMT数
    显然这样的数可以有无限个。
    FF博士现在想知道在所有小于n的正整数里面有多少个n的MMT数

    输入格式

    仅一行一个数,为n

    输出格式

     所有小于n的正整数里面有多少个n的MMT数

    测试样例1

    输入

    10

    输出

    3

    备注

    样例解释: 3个数分别是 4 6 8 
    gcd(n,x)的意思是求n和x的最大公约数

    对于50%的数据 n<=1000000
    对于100%的数据n<=maxlongint

    代码

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    inline int read(){
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int n,phi,tot,ans,num[500010],sum=1;
    int gcd(int a,int b){
        if(!b) return a;
        return gcd(b,a%b);
    }
    int main(){
        phi=n=read(); int tmp=n;
        for(int i=2;i*1ll*i<=tmp;++i){
            if(tmp%i==0){
                ++tot; phi=phi/i*(i-1);
                while(tmp%i==0){ ++num[tot]; tmp/=i;}
            }
            if(tmp==1) break;
        }
        if(tmp>1){phi=phi/tmp*(tmp-1); num[++tot]=1;}
        for(int i=1;i<=tot;++i)
        sum=sum*(num[i]+1);
        printf("%d
    ",n-phi-sum+1);
        return 0;
    }
        
  • 相关阅读:
    怎样解决:未找到路径“……”的控制器或该控制器未实现 IController?
    错误:org.springframework.jdbc.support.SQLErrorCodesFactory
    springbean的生命周期
    注解到处excel
    nio读取文件,输出文件
    AtomicReference
    唯一id
    hashmap1.7的死锁模拟
    数组模拟stack
    环形队列
  • 原文地址:https://www.cnblogs.com/huihao/p/7795579.html
Copyright © 2011-2022 走看看