• C


    Given a positive integer N, your task is to calculate the sum of the positive integers less than N which are not coprime to N. A is said to be coprime to B if A, B share no common positive divisors except 1.

    InputFor each test case, there is a line containing a positive integer N(1 ≤ N ≤ 1000000000). A line containing a single 0 follows the last test case.OutputFor each test case, you should print the sum module 1000000007 in a line.Sample Input

    3
    4
    0

    Sample Output

    0
    2

    给定一个正整数N,你的任务是计算小于N的正整数的和,这些正整数不是共圆到N的。

    输入

    对于每个测试用例,有一行包含一个正整数N(1≤N≤1000000000)。最后一个测试用例后面有一行包含一个0。

    输出

    对于每个测试用例,您应该在一行中打印sum模块1000000007。

    样例输入

    3.

    4

    0

    样例输出

    0

    2

    思路:本来以为这道题会是欧拉函数只不过返回的不是欧拉数,而是GCD(n,i)大于一的和,结果WA了

    想了想,以6为例

    1 2 3 4 5 6 其中 2 3 4 都是满足题意的,但是欧拉函数不会走4,他只会走它所有的质因子

    没有办法,只有看大佬题解,借鉴后看到了 求互质的数字和可以直接利用 n * enler( n) / 2求解,而此题要求的是非互质的,同样可以使用这个性质

    于是就一个欧拉函数,轻松AK,看到大佬用容斥写,哎还是见识太短,学的太少,小菜鸟今天又是队伍倒一。。。。。。。。

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <algorithm>
    #include <map>
    #define Mod 1000000007
    using namespace std;
    typedef long long ll;
    const  ll N = 1000000+10;
    int elh[N];
    int a;
    ll Euler(ll n)
    {
        ll res =n;
        for(int i=2;i<=n/i;i++)
        {
            if(n%i==0)
            {
                res = res-res/i;
            }
            while(n%i==0)n/=i;
        }
        if(n>1)res =res- res/n;
        return res%Mod;
    }
    int main()
    {
        while(~scanf("%lld",&a)&&a)
        {
            cout <<(a*(a-1-Euler(a))/2)%Mod<<endl;
        }
        return 0;
    }
    你的脸上风淡云轻,谁也不知道你的牙咬得有多紧。你走路带着风,谁也不知道你膝盖上仍有曾摔过的伤的淤青。你笑得没心没肺,没人知道你哭起来只能无声落泪。要让人觉得毫不费力,只能背后极其努力。我们没有改变不了的未来,只有不想改变的过去。
  • 相关阅读:
    java web图片显示到浏览器
    Spring MVC + jpa框架搭建,及全面分析
    spring常用jar包总结(转载)
    搭建基于Maven的SSM框架
    线程同步的几种方法
    HttpServlet容器响应Web客户流程
    forword 与 redirect
    Hibernate状态转换
    String StringBuffer StringBuilder 对比
    位运算符
  • 原文地址:https://www.cnblogs.com/wangzhe52xia/p/11394134.html
Copyright © 2020-2023  润新知