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互质的数的和,用总数减去互质的数的和,就得到了不互质的数的和。
 
代码:
 #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int mod=;
int main()
{
int n;
while(scanf("%d",&n)!=EOF&&n)
{
long long temp=n,eular=;
long long ans=(temp*(temp+)/)%mod;
for(int i=;i*i<=temp;i++)
if(temp%i==)
{
temp/=i;
eular*=i-;
while(temp%i==)
{
temp/=i;
eular*=i;
}
}
if(temp>) eular*=temp-;
eular%=mod;
temp=n;
long long w=(eular*temp/)%mod;
ans-=w;
ans-=n;
while(ans<) ans+=mod;
printf("%lld\n",ans);
}
return ;
}

Calculation 2

HDU 3501 Calculation 2(欧拉函数)的更多相关文章

  1. hdu 3501 Calculation 2 (欧拉函数)

    题目 题意:求小于n并且 和n不互质的数的总和. 思路:求小于n并且与n互质的数的和为:n*phi[n]/2 . 若a和n互质,n-a必定也和n互质(a<n).也就是说num必定为偶数.其中互质 ...

  2. hdu 3501 容斥原理或欧拉函数

    Calculation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. HDU3501 Calculation 2 [欧拉函数]

    题目传送门 Calculation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. HDU 1695 GCD (欧拉函数+容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. HDU 5430 Reflect(欧拉函数)

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=5430 从镜面材质的圆上一点发出一道光线反射NNN次后首次回到起点. 问本质不同的发射的方案数. 输入描述 ...

  6. hdu 5279 Reflect phi 欧拉函数

    Reflect Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/contest_chi ...

  7. HDU 1695 GCD(欧拉函数+容斥原理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:x位于区间[a, b],y位于区间[c, d],求满足GCD(x, y) = k的(x, ...

  8. HDU 1787 GCD Again(欧拉函数,水题)

    GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. hdu 1695 GCD(欧拉函数+容斥)

    Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD( ...

  10. hdu 2814 快速求欧拉函数

    /** 大意: 求[a,b] 之间 phi(a) + phi(a+1)...+ phi(b): 思路: 快速求欧拉函数 **/ #include <iostream> #include & ...

随机推荐

  1. DataTables选择行并删除(删除单行)

    $(document).ready(function() { var table = $('#example').DataTable(); $('#example tbody').on( 'click ...

  2. IQC IPQC FQC OQC QA QE SQE CQS QM 简介区别

    IQC Incoming quality control 来料质量控制.是企业产品过程质量的第一关,在这个部门工作的同事最主要的是要注意文件和资料,即:图纸 样品承认书 样板 ***配件检验规范 ,还 ...

  3. Speech Module

    Speech Module 1 FIRST_TEN = ["one", "two", "three", "four", ...

  4. 阻碍android程序员发展的几个原因

    1应该少看网上的android开发相关技术帖子,一个是错误很多,表达也不清楚,很多都是拷贝来拷贝去的.二个是技术变迁快,很多都过时了,经常看android技术相关帖子,养成了一种惰性,遇到问题不是去看 ...

  5. Java宝典(三)

    --说说ArrayList,Vector,LinkedList的存储性能和特性. --ArrayList和Vector都是使用数组方式存储数据,此数组元素数大于实际存储的数据以便增加和插入元素,他们都 ...

  6. Java Class 字节码文件结构详解

    Class字节码中有两种数据类型: 字节数据直接量:这是基本的数据类型.共细分为u1.u2.u4.u8四种,分别代表连续的1个字节.2个字节.4个字节.8个字节组成的整体数据. 表:表是由多个基本数据 ...

  7. ubuntu 16.04 Ubuntu 安装GDebi,从而安装deb文件

    其实在ubuntu直接双击deb文件就能安装,可是我现在装了ubuntu 16.04后,发现谷歌浏览器的deb和搜狗输入法的deb都不能直接双击安装,有点小问题. 但是安装GDebi软件后,直接在终端 ...

  8. python3-day1(文件操作)

    index: str.fomat() open file str.replace 一.新款str.fomat() 1.>>> '12'.zfill(5) '00012' 2.> ...

  9. MyWidget【简单自制控件】

    #coding=gbk from PyQt4 import QtGui,QtCore import random class MyWidget(QtGui.QWidget): def __init__ ...

  10. Objective-C(十八、谓语使用及实例说明)——iOS开发基础

    结合之前的学习笔记以及參考<Objective-C编程全解(第三版)>,对Objective-C知识点进行梳理总结.知识点一直在变,仅仅是作为參考,以苹果官方文档为准~ 十八.谓语的使用及 ...