首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【HDU】2824 - GCD(欧拉函数打表)

【HDU】2824 - GCD(欧拉函数打表)

作者头像
FishWang
发布2025-08-27 09:03:03
发布2025-08-27 09:03:03
10200
代码可运行
举报
运行总次数:0
代码可运行

点击打开题目

The Euler function

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

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

代码语言:javascript
代码运行次数:0
运行
复制
   3 100

Sample Output

代码语言:javascript
代码运行次数:0
运行
复制
   3042

Source

2009 Multi-University Training Contest 1 - Host by TJU

打一个 1 到 MAX 的欧拉函数表,表示 1 加到 i 的欧拉函数值。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
#define MAX 3000000
__int64 eu[MAX+5];
void Eular()
{
	eu[1] = 1;
	for (int i = 2 ; i <= MAX ; i++)
	{
		if (!eu[i])
		{
			for (int j = i ; j <= MAX ; j += i)
			{
				if (!eu[j])
					eu[j] = j;
				eu[j] -= eu[j] / i;
			}
		}
		eu[i] += eu[i-1];
	}
}
int main()
{
	Eular();
	int a,b;
	while (~scanf ("%d %d",&a,&b))
		printf ("%I64d\n",eu[b] - eu[a-1]);
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • The Euler function
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档