hdu 2824(欧拉函数)
2024-09-04 15:07:16
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)
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 ;
}
最新文章
- Shiro - 限制并发人数登录与剔除
- CentOS7.2设置zabbix
- [leetcode] Contains Duplicate II
- Linux系统下如何配置SSH?如何开启SSH
- Java基础知识强化之IO流笔记39:字符流缓冲流之复制文本文件案例01
- 【VB】StrConv函数 vbUnicode用法
- DBCP数据源的使用
- SQL语句使用时间和日期的函数
- Java 包装类Integer的值比较
- POJ 3171 Cleaning Shifts
- Windows10下安装Docker的步骤
- Vcomputer简介
- Mysq登陆后执行命令提示You must SET PASSWORD before executing this statement
- frei0r-1.6.1 for win32 133 DLLs
- C++内存空间
- 如何做自己的服务监控?spring boot 2.x服务监控揭秘
- centos7 管理开机启动:systemd
- 记录Linux下解压大文件时的一次奇葩经历
- Java理论学时第六节。课后作业。
- 20155235 《网络攻防》 实验八 Web基础
热门文章
- 02.VUE学习二之数据绑定
- 三分钟明白 Activity工作流 -- java运用
- Kilani and the Game CodeForces - 1105D (bfs)
- 裸奔着造房子——对政府禁止采购Win8系统的一些看法
- 回顾Scrum学习:《Scrum实战》第4次课【全职的Scrum Master】作业
- loj2291 「THUSC 2016」补退选
- 五分钟搞定Linux容器
- 极简Node教程-七天从小白变大神(一:你需要Express)
- java环境变量配置(Windows &; Linux)
- Python+Selenium练习篇之14-获取当前页面的title