zoukankan      html  css  js  c++  java
  • HDU 3501 Calculation 2(欧拉函数)

    Calculation 2
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    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.
     

    Input

    For 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.
     

    Output

    For 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互质的数的和模1000000007的值。
     
    解题思路:
    欧拉函数,先求出小于n且与n互质的数的和,用总数减去互质的数的和,就得到了不互质的数的和。
     
    代码:
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 using namespace std;
     5 const int mod=1000000007;
     6 int main()
     7 {
     8     int n;
     9     while(scanf("%d",&n)!=EOF&&n)
    10     {
    11         long long temp=n,eular=1;
    12         long long ans=(temp*(temp+1)/2)%mod;
    13         for(int i=2;i*i<=temp;i++)
    14             if(temp%i==0)
    15             {
    16                 temp/=i;
    17                 eular*=i-1;
    18                 while(temp%i==0)
    19                 {
    20                     temp/=i;
    21                     eular*=i;
    22                 }
    23             }
    24         if(temp>1) eular*=temp-1;
    25         eular%=mod;
    26         temp=n;
    27         long long w=(eular*temp/2)%mod;
    28         ans-=w;
    29         ans-=n;
    30         while(ans<0) ans+=mod;
    31         printf("%lld
    ",ans);
    32     }
    33     return 0;
    34 }
    Calculation 2
  • 相关阅读:
    驱动下的异常处理
    头文件 .h 与源文件 .ccp 的区别
    驱动程序进阶篇
    驱动中链表的使用
    内存操作相关内核 API 的使用
    链表的概念、建立、删除与插入
    编写简单的 NT 式驱动程序的加载与卸载工具
    驱动程序入门篇
    c++ 指针的简单用法
    CTL_CODE 宏 详解
  • 原文地址:https://www.cnblogs.com/I-love-HLD/p/4624723.html
Copyright © 2011-2022 走看看