zoukankan      html  css  js  c++  java
  • hdu 1286 找新朋友 (欧拉函数)

    Description

    新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来。

    Input

    第一行是测试数据的组数CN(Case number,1<CN<10000),接着有CN行正整数N(1<n<32768),表示会员人数。

    Output

    对于每一个N,输出一行新朋友的人数,这样共有CN行输出。 

    Sample Input

    2
    25608
    24027

    Sample Output

    7680
    16016

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<queue>
    #include<stack>
    #include<cmath>
    using namespace std;
    #define INF 0x3f3f3f3f
    #define maxn 2100
    int Euler(int x)
    {
        int i,res = x;
        for(i = 2;i*i<=x;i++)
        {
            if(x%i==0)
                res = res/i*(i-1);
            while(x%i==0)
                x/=i;
        }
        if(x>1)
            res = res / x*(x-1);
        return res;
    }//欧拉函数,寻找从1到n与n互质的数
    int main()
    {
        int t,n;
        scanf("%d",&t);
        while(t--)
        {
           scanf("%d",&n);
            printf("%d
    ",Euler(n));
        }
        return 0;
    }
  • 相关阅读:
    P3383 【模板】线性筛素数
    【模板】矩阵乘法快速幂
    【模板】线性筛素数
    【模板】快速幂
    【模板】归并排序求逆序对
    【模板】归并排序模板
    luogu 1084 疫情控制
    luogu 3155 [CQOI2009]叶子的染色
    luogu 1453 城市环路
    luogu 2607 [ZJOI2008]骑士
  • 原文地址:https://www.cnblogs.com/biu-biu-biu-/p/5731513.html
Copyright © 2011-2022 走看看