• hdu 2654 Be a hero


    ()Become A Hero

    Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 295    Accepted Submission(s): 83


    Problem Description
    Lemon wants to be a hero since he was a child. Recently he is reading a book called “Where Is Hero From” written by ZTY. After reading the book, Lemon sends a letter to ZTY. Soon he recieves a reply.

    Dear Lemon,
    It is my way of success. Please caculate the algorithm, and secret is behind the answer. The algorithm follows:
    Int Answer(Int n)
    {
    .......Count = 0;
    .......For (I = 1; I <= n; I++)
    .......{
    ..............If (LCM(I, n) < n * I)
    ....................Count++;
    .......}
    .......Return Count;
    }
    The LCM(m, n) is the lowest common multiple of m and n.
    It is easy for you, isn’t it. 
    Please hurry up!
    ZTY

    What a good chance to be a hero. Lemon can not wait any longer. Please help Lemon get the answer as soon as possible. 
     
    Input
    First line contains an integer T(1 <= T <= 1000000) indicates the number of test case. Then T line follows, each line contains an integer n (1 <= n <= 2000000).
     
    Output
    For each data print one line, the Answer(n).
     
    Sample Input
    1
    1
     
    Sample Output
    0
     
    题解:
    题意是求满足lcm(i,n)<i*n条件的 i 的个数
    因为lum(i,n)=(i*n)/gcd(i,n);
    所以     lcm(i,n)<i*n   <<===>>gcd(i,n)>1
    即求i<n中 i, n不互质的个数
    (不互质的个数=n-φ(n))
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    ll euler(ll x)
    {
        ll res = x;
        for(int 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;
    }
    
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            ll n;
            scanf("%I64d",&n);
            printf("%I64d
    ",n-euler(n));
        }
        return 0;
    }
     
  • 相关阅读:
    python 特性 property
    OWASP_ZAP集成渗透测试和漏洞工具
    openvas开放式漏洞评估系统
    SSL协议(安全套接层协议)
    windows下如何查看端口,关闭端口,开启端口
    网络端口通俗的说是啥意思?
    APP安全性测试总结--网上转载
    android填满手机内存的方法
    adb push和adb install区别
    Maven打包同一个jar有不同的:版本+时间戳(解决思路)
  • 原文地址:https://www.cnblogs.com/-citywall123/p/10171035.html
Copyright © 2020-2023  润新知