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. FLASH MAGIC LPC ISP下载方式说明

    硬件:EASYARM2131 开发板软件:FLASH MAGIC     下载地址:http://www.flashmagictool.com/程序:Demo2131.hex LPC的ISP下载方式, ...

  2. vc++深入跟踪MFC程序的执行流程

    在MFC程序设计的学习过程中最令人感到难受,甚至于有时会动摇学习者信心的就是一种对于程序的一切细节都没有控制权的感觉.这种感觉来源于学习者不知道一个MFC程序是如何运行起来的(即一个MFC程序的执行流 ...

  3. click through rate prediction

    包括内容如下图: 使用直接估计法,置信区间置信率的估计: 1.使用二项分布直接估计 $p(0.04<\hat{p}<0.06) = \sum_{0.04n\leq k \leq 0.06n ...

  4. C# 连接 Mysql 中文乱码问题

    网上有很多解决乱码的方法,什么 set names utf8   .什么在插入数据前进行编码,亲自试了都没有效果,在网上寻觅了很久,终于找到一种方法,并亲试成功: 首先要保证你的数据库是UTF8字符集 ...

  5. CodeForces 111B - Petya and Divisors 统计..想法题

    找每个数的约数(暴力就够了...1~x^0.5)....看这约数的倍数最后是哪个数...若距离大于了y..统计++...然后将这个约数的最后倍数赋值为当前位置...好叼的想法题.... Program ...

  6. matlab如何写一个类

    类是一种数据类型,与普通的数据类型不同的是类不仅包含数据,还包含对数据的操作,类把数据和数据操作方法封装在一起,作为一个整体参与程序的运行.类具有可继承性,创建一个新的类的时候,可以在一个基类中添加成 ...

  7. mysql存储过程和触发器的应用

    ***********[mysql 存储过程和触发器 -- 别安驹]********************* 1.什么情况下使用存储过程? 完成一些比较麻烦的逻辑,比如多表在mysql端的cpu很空 ...

  8. java中int和Integer的区别

    Integer与int的种种比较你知道多少?  转载自http://www.cnblogs.com/liuling/archive/2013/05/05/intAndInteger.html 如果面试 ...

  9. 字符数组什么时候要加‘\0’

    当字符数组以单个字符进行赋值时: char ch[10]; ch[10]={'a','b',---'\0'}; 或者用for循环进行赋值时: for (i=0; i<9; i++){ch[i]= ...

  10. leetcode Combination Sum python

    Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...