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
题解:打表水过;
代码:
 #include<stdio.h>
#include<string.h>
const int MAXN= ;
__int64 dp[MAXN];
int main(){
memset(dp,,sizeof(dp));
dp[]=;
for(int i=;i<MAXN;i++){
if(dp[i])continue;
for(int j=i;j<MAXN;j+=i){
if(!dp[j])dp[j]=j;
dp[j]=dp[j]/i*(i-);
}
}
for(int i=;i<MAXN;i++)dp[i]+=dp[i-];
int a,b;
while(~scanf("%d%d",&a,&b))printf("%I64d\n",dp[b]-dp[a-]);
return ;
}

java超内存:

package com.lanqiao.week1;

import java.util.Scanner;

public class hdu2824 {
private static Scanner cin = null;
private static int MAXN = 3000010;
static Long[] d = new Long[MAXN];
static{
cin = new Scanner(System.in); } public static void main(String[] args) {
int a, b;
for(int i = 1; i < MAXN; i++){
d[i] = 0L;
}
for(int i = 2; i < MAXN; i++){
if(d[i] == 0){
for(int j = i; j < MAXN; j += i){
if(d[j] == 0)
d[j] = 1L * j;
d[j] = d[j] / i * (i - 1);
}
}
}
for(int i = 2; i < MAXN; i++){
d[i] += d[i - 1];
}
while(cin.hasNext()){
a = cin.nextInt();
b = cin.nextInt();
System.out.println(d[b] - d[a - 1]);
}
}
}

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

  1. hdu 2824 The Euler function(欧拉函数)

    题目链接:hdu 2824 The Euler function 题意: 让你求一段区间的欧拉函数值. 题解: 直接上板子. 推导过程: 定义:对于正整数n,φ(n)是小于或等于n的正整数中,与n互质 ...

  2. hdu 2824 The Euler function 欧拉函数打表

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)

    6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...

  4. (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/Othe ...

  5. HDU - 2824 The Euler function 欧拉函数筛 模板

    HDU - 2824 题意: 求[a,b]间的欧拉函数和.这道题卡内存,只能开一个数组. 思路: ϕ(n) = n * (p-1)/p * ... 可利用线性筛法求出所有ϕ(n) . #include ...

  6. Euler:欧拉函数&素数筛

    一.欧拉函数 欧拉函数是小于x的整数中与x互质的数的个数,一般用φ(x)表示. 通式:   其中p1, p2……pn为x的所有质因数,x是不为0的整数. 比如x=12,拆成质因数为12=2*2*3, ...

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

    题目链接: GTW likes function Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 131072/131072 K (J ...

  8. HDU 5597 GTW likes function 欧拉函数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5597 题意: http://bestcoder.hdu.edu.cn/contests/contes ...

  9. LightOJ1370 Bi-shoe and Phi-shoe —— 欧拉函数

    题目链接:https://vjudge.net/problem/LightOJ-1370 1370 - Bi-shoe and Phi-shoe    PDF (English) Statistics ...

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

    /* 题意:(n)表示小于n与n互质的数有多少个,给你两个数a,b让你计算a+(a+1)+(a+2)+......+b; 初步思路:暴力搞一下,打表 #放弃:打了十几分钟没打完 #改进:欧拉函数:具体 ...

随机推荐

  1. data stage走起

    如题,希望以后可以找到相应的工作.(已经工作3年以上了)

  2. Sass使用教程

    sass官网: http://sass-lang.com/ http://sass-lang.com/documentation/file.SASS_REFERENCE.html Sass和Scss的 ...

  3. Javascript禁止父元素滚动条滚动, pc、移动端均有效

    在网页中经常会遇到这样的场景, 网页比较长有滚动条, 然后网页内的某个内容块里面的内容也比较长, 也具有滚动条.当鼠标移到内容块中使用滚动条来滚动查看内容到达底部或头部的时候,父元素的滚动条也就开始滚 ...

  4. Android UI ActionBar功能-ActionBarSherlock 的使用

    ActionBarSherlock实现了在ActionBar上添加一个下拉菜单的功能,也是App常用的功能之一: ActionBarSherlock是第三方提供的一个开源类库,下载地址:http:// ...

  5. 网易云课堂_程序设计入门-C语言_期末考试编程题

    1 字数统计(10分) 题目内容: 你的程序要读入一篇英文文章,然后统计其中的单词数来输出.需要统计的数据为: 总的单词数量: 含有1个字母到10个字母的单词的数量. 单词和单词的间隔是由以下标点符号 ...

  6. php获取服务器地址

    if ( isset( $_SERVER['HTTP_X_FORWARDED_HOST'] ) ) { // Support ProxyPass        $t_hosts = explode( ...

  7. 如何用C#把Doc文档转换成rtf格式

    先在项目引用里添加上对Microsoft Word 9.0 object library的引用 using System; namespace DocConvert { class DoctoRtf ...

  8. CM_RESOURCE_LIST structure

    The CM_RESOURCE_LIST structure specifies all of the system hardware resources assigned to a device. ...

  9. javaScript 工作必知(十) call apply bind

    call  每个func 都会继承call apply等方法. function print(mesage) { console.log(mesage); return mesage; } print ...

  10. Ubuntu Android Studio 无法通过起动器开启

    问题: 1.可以通过终端开启 2.通过Android-Studio建立的Application无法启动, 提示 No JDK found. Please validate either STUDIO_ ...