The Euler function

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5235    Accepted Submission(s): 2225

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>
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
typedef long long LL;
const int N =;
LL euler[N];
//LL sum[N];
void getEuler()
{
memset(euler,,sizeof(euler));
euler[] = ;
for(int i = ; i <= N; i++){
if(!euler[i])
for(int j = i; j <= N; j+= i)
{
if(!euler[j])
euler[j] = j;
euler[j] = euler[j]/i*(i-);
}
//sum[i]=sum[i-1]+(LL)euler[i];
}
} int main()
{
getEuler();
int a,b;
while(~scanf("%d%d",&a,&b)){
LL sum = ;
for(int i=a;i<=b;i++){
sum+=euler[i];
}
printf("%lld\n",sum);
}
return ;
}

最新文章

  1. Shiro - 限制并发人数登录与剔除
  2. CentOS7.2设置zabbix
  3. [leetcode] Contains Duplicate II
  4. Linux系统下如何配置SSH?如何开启SSH
  5. Java基础知识强化之IO流笔记39:字符流缓冲流之复制文本文件案例01
  6. 【VB】StrConv函数 vbUnicode用法
  7. DBCP数据源的使用
  8. SQL语句使用时间和日期的函数
  9. Java 包装类Integer的值比较
  10. POJ 3171 Cleaning Shifts
  11. Windows10下安装Docker的步骤
  12. Vcomputer简介
  13. Mysq登陆后执行命令提示You must SET PASSWORD before executing this statement
  14. frei0r-1.6.1 for win32 133 DLLs
  15. C++内存空间
  16. 如何做自己的服务监控?spring boot 2.x服务监控揭秘
  17. centos7 管理开机启动:systemd
  18. 记录Linux下解压大文件时的一次奇葩经历
  19. Java理论学时第六节。课后作业。
  20. 20155235 《网络攻防》 实验八 Web基础

热门文章

  1. 02.VUE学习二之数据绑定
  2. 三分钟明白 Activity工作流 -- java运用
  3. Kilani and the Game CodeForces - 1105D (bfs)
  4. 裸奔着造房子——对政府禁止采购Win8系统的一些看法
  5. 回顾Scrum学习:《Scrum实战》第4次课【全职的Scrum Master】作业
  6. loj2291 「THUSC 2016」补退选
  7. 五分钟搞定Linux容器
  8. 极简Node教程-七天从小白变大神(一:你需要Express)
  9. java环境变量配置(Windows &amp; Linux)
  10. Python+Selenium练习篇之14-获取当前页面的title