hdoj 3501

  

Problem 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互质的数的总和为φ(x) * x / 2。(n>1)

时间: 2024-11-24 11:15:32

hdoj 3501的相关文章

HDOJ 3501 Calculation 2

题目链接 分析: 要求的是小于$n$的和$n$不互质的数字之和...那么我们先求出和$n$互质的数字之和,然后减一减就好了... $\sum _{i=1}^{n} i[gcd(i,n)==1]=\frac{n\phi(n)}{2}$ 考虑$gcd(n,i)=1$,那么必然有$gcd(n,n-i)=1$,然后发现如果把$gcd(n,i)=1$和$gcd(n,n-i)=1$凑到一起会出现$n$,这样的有$\frac{\phi(n)}{2}$对... 代码: #include<algorithm>

hdoj 3501 -Calculation 2 (欧拉函数)

Calculation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3305    Accepted Submission(s): 1367 Problem Description Given a positive integer N, your task is to calculate the sum of the positi

HDOJ 3501 Calculation 2(欧拉函数拓展——求非互质数和)

Calculation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2548    Accepted Submission(s): 1064 Problem Description Given a positive integer N, your task is to calculate the sum of the posit

hdoj 3501 Calculation 2 【欧拉函数】

Calculation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2306    Accepted Submission(s): 976 Problem Description Given a positive integer N, your task is to calculate the sum of the positi

【HDOJ】4328 Cut the cake

将原问题转化为求完全由1组成的最大子矩阵.挺经典的通过dp将n^3转化为n^2. 1 /* 4328 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <stack> 9 #include <vector>

POJ Xiangqi 4001 &amp;&amp; HDOJ 4121 Xiangqi

题目链接(POJ):http://poj.org/problem?id=4001 题目链接(HDOJ):http://acm.hdu.edu.cn/showproblem.php?pid=4121 Xiangqi Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1108   Accepted: 299 Description Xiangqi is one of the most popular two-player boa

【HDOJ】4956 Poor Hanamichi

基本数学题一道,看错位数,当成大数减做了,而且还把方向看反了.所求为最接近l的值. 1 #include <cstdio> 2 3 int f(__int64 x) { 4 int i, sum; 5 6 i = sum = 0; 7 while (x) { 8 if (i & 1) 9 sum -= x%10; 10 else 11 sum += x%10; 12 ++i; 13 x/=10; 14 } 15 return sum; 16 } 17 18 int main() { 1

HDOJ 4901 The Romantic Hero

DP....扫两遍组合起来 The Romantic Hero Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 547    Accepted Submission(s): 217 Problem Description There is an old country and the king fell in love with a

【HDOJ】1099 Lottery

题意超难懂,实则一道概率论的题目.求P(n).P(n) = n*(1+1/2+1/3+1/4+...+1/n).结果如果可以除尽则表示为整数,否则表示为假分数. 1 #include <cstdio> 2 #include <cstring> 3 4 #define MAXN 25 5 6 __int64 buf[MAXN]; 7 8 __int64 gcd(__int64 a, __int64 b) { 9 if (b == 0) return a; 10 else return