The Euler function(欧拉函数)

The Euler function

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 39   Accepted Submission(s) : 19

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are smaller than n and coprime to n, and this function has a lot of beautiful characteristics. Here comes a very easy question: suppose you are given a, b, try to calculate (a)+ (a+1)+....+ (b)

Input

There are several test cases. Each line has two integers a, b (2<a<b<3000000).

Output

Output the result of (a)+ (a+1)+....+ (b)

Sample Input

3 100

Sample Output

3042题解:打表水过;代码:
 1 #include<stdio.h>
 2 #include<string.h>
 3 const int MAXN= 3000010;
 4 __int64 dp[MAXN];
 5 int main(){
 6     memset(dp,0,sizeof(dp));
 7     dp[1]=1;
 8     for(int i=2;i<MAXN;i++){
 9         if(dp[i])continue;
10         for(int j=i;j<MAXN;j+=i){
11             if(!dp[j])dp[j]=j;
12             dp[j]=dp[j]/i*(i-1);
13         }
14     }
15     for(int i=2;i<MAXN;i++)dp[i]+=dp[i-1];
16     int a,b;
17     while(~scanf("%d%d",&a,&b))printf("%I64d\n",dp[b]-dp[a-1]);
18         return 0;
19 } 
时间: 2024-10-23 03:32:15

The Euler function(欧拉函数)的相关文章

hdu-2824 The Euler function(欧拉函数)

题目链接: The Euler function Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4987    Accepted Submission(s): 2098 Problem Description The Euler function phi is an important kind of function in numb

hdu 2824 The Euler function 欧拉函数打表

The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are sm

(hdu step 7.2.1)The Euler function(欧拉函数模板题——求phi[a]到phi[b]的和)

题目: The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 166 Accepted Submission(s): 96   Problem Description The Euler function phi is an important kind of function in number theory

hdu-5597 GTW likes function(欧拉函数+找规律)

题目链接: GTW likes function Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others) Problem Description Now you are given two definitions as follows. f(x)=∑xk=0(−1)k22x−2kCk2x−k+1,f0(x)=f(x),fn(x)=f(fn−1(x))(n≥1) Note that

HDU 2588 GCD【欧拉函数的运用】

http://acm.hdu.edu.cn/showproblem.php?pid=2588 题意:输入s个数 输入n  m  表示从1到n的数与n的公约数大于m的数的个数 思路: 首先找出n的所有大于m的公约数k,然后求出每个对应的n/k的euler(欧拉函数)即小于n/k的数与n/k互质的个数,那么这些数与n/k互质且小于n/k,那么这些与n/k互质的数  乘以k之后那么就变成了与n公约数为k的数(k>m)   把所有的euler(n/k)相加即是答案    这是参考别人的思路的. #inc

hdu2824 The Euler function(欧拉函数个数)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 欧拉函数性质: 1:(百科):http://baike.baidu.com/link?url=r-yneKCCyS9N6bhbQCqiZX0V2OCYq9r7iHSzHTSs03H7qRvu1OfUzlOxfVEs2PmR 2:http://www.cppblog.com/doer-xee/archive/2009

The Euler function(线性筛欧拉函数)

/* 题意:(n)表示小于n与n互质的数有多少个,给你两个数a,b让你计算a+(a+1)+(a+2)+......+b; 初步思路:暴力搞一下,打表 #放弃:打了十几分钟没打完 #改进:欧拉函数:具体证明看po主的博客 ^0^ #超时:这里直接用欧拉函数暴力搞还是不可以的,用到线性筛欧拉函数,这里总和爆int,要用long long */ #include<bits/stdc++.h> #define ll long long using namespace std; /***********

The Euler function(欧拉函数筛)

这题用欧拉函数会超时,要用函数筛. 解析:(转) 定义:对于正整数n,φ(n)是小于或等于n的正整数中,与n互质的数的数目. 例如:φ(8)=4,因为1,3,5,7均和8互质. 性质:1.若p是质数,φ(p)= p-1. 2.若n是质数p的k次幂,φ(n)=(p-1)*p^(k-1).因为除了p的倍数都与n互质 3.欧拉函数是积性函数,若m,n互质,φ(mn)= φ(m)φ(n). 根据这3条性质我们就可以推出一个整数的欧拉函数的公式.因为一个数总可以写成一些质数的乘积的形式. E(k)=(p1

hdu2824 The Euler function O(n)求欧拉函数

hdu2824 The Euler function O(n)求欧拉函数 1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std ; 4 5 const int N = 3000011 ; 6 int l,r ; 7 int prime[ 300011 ],phi[N] ; 8 ll sum ; 9 bool f[N] ; 10 11 inline void Euler_init(int NN) 12 {

HDU2824 The Euler function(欧拉函数)

题目求φ(a)+φ(a+1)+...+φ(b-1)+φ(b). 用欧拉筛选法O(n)计算出n以内的φ值,存个前缀和即可. φ(p)=p-1(p是质数),小于这个质数且与其互质的个数就是p-1: φ(p*a)=(p-1)*φ(a)(p是质数且p|a),因为欧拉函数是积性函数,φ(p*a)=φ(p)*φ(a): φ(p*a)=p*φ(a)(p是质数且p不能整除a),不知怎么理解.. 1 #include<cstdio> 2 #include<cstring> 3 using names