LightOJ1007---Mathematically Hard (欧拉函数)

路径跟踪 | 图解路径跟踪PID算法(附ROS C++/Python/Matlab仿真) PID控制是一种经典的控制算法,广泛应用于各种工业场景。在基于PID的局部路径规划中,希望机器人能快速跟踪上预设的轨迹。本文介绍PID控制的基本原理,并基于PID控制律设计路径跟踪算法,最后通过ROS C++/Python/Matlab进行仿真实现,加深理解 阅读详情

Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable.

In this problem, you will be given two integers a and b. You have to find the summation of the scores of the numbers from a to b (inclusive). The score of a number is defined as the following function.

score (x) = n2, where n is the number of relatively prime numbers with x, which are smaller than x

For example,

For 6, the relatively prime numbers with 6 are 1 and 5. So, score (6) = 22 = 4.

For 8, the relatively prime numbers with 8 are 1, 3, 5 and 7. So, score (8) = 42 = 16.

Now you have to solve this task.
Input

Input starts with an integer T (≤ 105), denoting the number of test cases.

Each case will contain two integers a and b (2 ≤ a ≤ b ≤ 5 * 106).
Output

For each case, print the case number and the summation of all the scores from a to b.
Sample Input

Output for Sample Input

3

6 6

8 8

2 20

Case 1: 4

Case 2: 16

Case 3: 1237
Note

Euler’s totient function applied to a positive integer n is defined to be the number of positive integers less than or equal to n that are relatively prime to n. is read “phi of n.”

Given the general prime factorization of , one can compute using the formula

把1-5000000的欧拉函数筛选出来存起来,然后预处理前缀和,注意long long会溢出,要用unsigned long long

/*************************************************************************
    > File Name: LightOJ1007.cpp
    > Author: ALex
    > Mail: zchao1995@gmail.com 
    > Created Time: 2015年06月04日 星期四 17时41分21秒
 ************************************************************************/

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>

using namespace std;

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

static const int N = 5000010;
int phi[N];
unsigned long long Arr[N];

void getphi() {
    for (int i = 1; i <= 5000000; ++i) {
        Arr[i] = i;
    }
    for (int i = 2; i <= 5000000; ++i) {
        if (Arr[i] == i) {
            if (5000000 / i < i) {
                break;
            }
            for (int j = i * i; j <= 5000000; j += i) {
                Arr[j] = i;
            }
        }
    }
    phi[1] = 1;
    for (int i = 2; i <= 5000000; ++i) {
        phi[i] = phi[i / Arr[i]];
        if ((i / Arr[i]) % Arr[i]) {
            phi[i] *= (Arr[i] - 1);
        }
        else {
            phi[i] *= Arr[i];
        }
    }
}

int main() {
    getphi();
    int t, icase = 1;
    Arr[0] = 0;
    for (int i = 1; i <= 5000000; ++i) {
        Arr[i] = Arr[i - 1] + (unsigned long long)phi[i] * phi[i];
    }
    scanf("%d", &t);
    while (t--) {
        int a, b;
        scanf("%d%d", &a, &b);
        printf("Case %d: %llu\n", icase++, Arr[b] - Arr[a - 1]); 
    }
    return 0;
}
Python爬虫实战:百度贴吧帖子与评论抓取全攻略(附舆情分析技巧) 基础配置# 要爬取的贴吧名称(替换成自己需要的,比如“XX手游吧”)TIEBA_NAME = "XX手游"# 分页参数(每页50条帖子,可根据需求调整)PAGE_NUM = 3 # 爬取前3页帖子,共150条# 请求头(从浏览器复制自己的,更真实)Win64; 阅读详情

相关推荐

从零解析:富斯i6遥控器与STM32的IBUS协议通信实战

本文详细解析了富斯i6遥控器与STM32通过IBUS协议通信的实战指南,涵盖硬件准备、协议解析、驱动实现及常见问题解决。特别适合机器人及智能小车开发者,提供低成本、高可靠性的无线控制方案,助力快速实现多通道控制功能。

weixin_29193359的博客 444

LightOJ1007 - Mathematically Hard

1014 - Ifter Party PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB I have an Ifter party at the 5th day of Ramadan for the contesta

追梦的Anker 959

三角洲行动交易行自动化脚本

DFMarketBot - 三角洲行动自动交易助手 DFMarketBot是一款专为三角洲行动游戏设计的交易行自动化工具,通过OCR识别和鼠标模拟实现自动补卡、补子弹功能。项目采用Python开发,支持Windows平台,主要功能包括: 自动检测并购买指定物品(房卡/子弹) 价格监控与智能购买(低于设定价格自动下单) 自定义购买数量与次数限制 支持窗口/无窗口两种游戏模式 使用前需安装Tesseract OCR引擎并配置游戏为1920*1080分辨率。通过JSON文件可灵活配置监控物品清单、理想价格和购买策

愤怒的阿木木的博客 3万+

LightOJ - 1007-Mathematically Hard

题目: Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable.In this problem, you will be given two integers a and b. You have to find the summat

AC即性感 372

Jasper Report使用JSON数据源创建报表

最近在做一个项目小功能,表单结案要生成PDF报表。 起初,想用HTML模板(art-template模板引擎)编写,利用浏览器的打印功能保存成pdf文件下载。但是HTML编写好的模板,页码、页眉、页脚设置有坑,表单内容中的表格较多,表格不能设置跨页,导致跨页的表格内容与页眉重叠,没能解决这个问题。 于是,转战研究Jasper report生成报表,用更加专业的报表生成工具来做。刚开始,也是跌跌撞撞,遇到了很多问题,因为觉得没有退路了,必须要用这个搞出来,所以就硬着头皮去找各种资料。 主要使用的json

xiaogege2012的专栏 3323

Cadence Allegro PCB文件对比实战:3分钟搞定两份设计差异(附颜色标注技巧)

本文详细介绍了如何高效使用Cadence Allegro的Design Compare功能进行PCB文件差异对比。通过实战工作流,可在3分钟内精准定位并理解两份设计在布局、布线、元件等方面的关键差异,并分享了自定义颜色标注技巧,帮助工程师快速聚焦重要修改,提升设计评审与团队协作效率。

weixin_29248653的博客 390

lightoj 1007 - Mathematically Hard 欧拉函数

题意:求[a,b]范围内所有整数的欧拉函数的平方和。欧拉函数:求不大于其本身的与其互质的数的个数。 题解:预处理,欧拉函数筛选下,之后保存前n项和,sum[n]。答案就是ans=sum[b]-sum[a-1]。 注意: 1.之后结果很大,需要用无符号64位整数,unsigned long long。lightoj好像不能用__int64。 2.内存足,开两个5e6的数组会爆内存,所以前n项

冷月之殇 1273

Ansys -PEmag 平面变压器仿真与circuit电路模型验证

ansys 软件集成了电路、磁路、PCB参数提取,结构参数提取等功能仿真,基于内置模块的功能参数的仿真后可以提取出主要关键参数,寄生参数,频域响应参数等。该软件的优势在于能够将所有的仿真参数导出为电路模型文件,可以在自带的模块中仿真也可以导出在其他第三方软件中仿真,比如matlab-simulink文件扥。主要介绍ANSYS插件的使用,对PEmag做了详细使用说明并通过案例得到对用的变压器参数;基于变压器参数再将其磁路模型导入到电路中进行建模仿真,实现PEmag与circuit的联合仿真。

weixin_41609745的博客 3026

LightOJ1007(欧拉函数)

Mathematically Hard Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable. In this problem, you will be given two integers a and b. You have...

weixin_33937913的博客 181

mbed驱动st7789屏幕-硬件选择及连接(1)

在单片机项目中,交互性至关重要,而视觉感知是用户交互的直接体现。本期专栏介绍了如何使用mbed平台驱动ST7789型号的TFT屏幕,以显示字符、汉字和图像。由于针对STM32L432KC的mbed驱动库尚未完整,作者自行编写了一个基于mbed的ST7789屏幕驱动库,并将在专栏中提供全代码及使用指南。

weixin_64524066的博客 392

【SpringBoot 3.x 第56节】再见 Feign?原生 HTTP 接口强势上位,这才是微服务调用的正确姿势!

🏆本文收录于《滚雪球学SpringBoot 3》,专门攻坚指数提升,本年度国内最系统+最专业+最详细(永久更新)。    本专栏致力打造最硬核 SpringBoot3 从零基础到进阶系列学习内容,🚀均为全网独家首发,打造精品专栏,专栏持续更新中…欢迎大家订阅持续学习。 如果想快速定位学习,可以看这篇【SpringBoot3教程导航帖】,你想学习的都被收集在内,快速投入学习!!两不误。    若还想学习更多,可直接前往《滚雪球学SpringBoot(全版本合集)》,涵盖SpringBoot所有版本教学文章

**My Coding Family** 1026

LightOJ 1007(欧拉函数打表+前缀和)

Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable. In this problem, you will be given two integers a and b. You have to find the summatio...

Dog_dream的博客 364

Vue3 - 解决报错 Uncaught (in promise) DOMException: Failed to execute ‘insertBefore‘ on ‘Node‘: The node

vue3,报错,vue3报错,Uncaught(inpromise)DOMException:Failedtoexecute'insertBefore'on'Node':Thenodebeforewhichthenewnodeistobeinsertedisnotachildofthisnode,如何解决这个错误,动态渲染,v-if,v-show,insertBefore,详细解决方法,vue3未能在“Node”上执行“insertBefore”:要插入

🏆 前端领域优质创作者 1万+

LightOJ 1007 Mathematically Hard 欧拉函数

题目:http://www.lightoj.com/volume_showproblem.php?problem=1007 题意:对于数x,定义score(x) = n^2,n是1~x中与x互质的数的个数。然后求a~b之间所有数的score()之和 思路:欧拉函数,很裸了,但结果会溢出,用long long也会溢出,用unsigned long long才可以,然后输出格式控制用%llu。。。

弱智就要多努力 445

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

LightOJ 1007 Mathematically Hard(欧拉函数)

Mathematically Hard Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable. In this problem, you will be given two integers a and b. You have t...

Tan_JX 187

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

LightOJ-1007-Mathematically Hard [欧拉函数]

题目传送门题意:求下从a到b的所有数的欧拉函数的平方和。欧拉函数:小于n的与n互质的数的个数。思路:预处理筛选,求前缀和。#include <bits/stdc++.h>using namespace std;unsigned long long ans[5000100]; void init() { ans[0] = 0; ans[1] = 1; for (int i =

裤头是叫裤头的裤头 338

【题解】LightOJ1007Mathematically Hard 欧拉函数

题目链接 //预处理出欧拉函数 #include&amp;lt;cstdio&amp;gt; #include&amp;lt;cstring&amp;gt; typedef unsigned long long ll; const int N=5e6+10; ll phi[N]; void init() { memset(phi,0,sizeof(phi)); phi[1]=1; int i,j;...

翻过这座山,他们就会听到你的故事 169

lightoj 1007Mathematically Hard (欧拉函数水题)

题目链接:here 如题:水题; 但是好坑。。。。。。。 注意:①筛法欧拉函数先除再乘,可使用int数组(这题开两个 unsigned long long 爆内存)或者sum数组和euler数组使用同一个数组             ②long long 居然不能过,long long居然不能过,long long不能过,所以要用unsiged long long

destiny546的博客 380

lightoj 1007 - Mathematically Hard 欧拉函数

求a,b之间的欧拉函数的平方和。 直接筛选法求出欧拉函数,然后来个前缀和。 注意会爆ll,开成ull #include using namespace std; #define N 5010000 #define ll long long #define ull unsigned long long int phi[N+20]; ll ans[N+20]; void euler() {

446

LightOJ1007 Mathematically Hard 欧拉函数+前缀和

Description Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable. In this problem, you will be given two integers a and b. You have to fi

Megumin的博客 644

LightOj1007 - Mathematically Hard (欧拉函数)

题意:http://www.lightoj.com/volume_showproblem.php?problem=1007 求[a,b]范围内所有整数的欧拉函数的平方和。欧拉函数:求不大于其本身的与其互质的数的个数。 第一次用这个 结果会爆long long,要用unsigned long long %llu形式; #include<cstdio> #include&l...

weixin_30608503的博客 130

LIGHTOJ 1007 – MATHEMATICALLY HARD【欧拉函数】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1007题意:打表欧拉函数即可;代码:#include<stdio.h> #include<iostream> #include<math.h> #include<stdlib.h> #include<ctype.h> #include<alg

mfcheer 511

LightOJ - 1007 Mathematically Hard(欧拉函数质数打表)

LINK Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable. In this problem, you will be given two integers a and b. You have to find the summation of the scores of the numbers from a to b (inclusiv

大聪明的博客 184

lightoj 1007 - Mathematically Hard 欧拉函数应用

题意:求[a,b]内所有与b互质个数的平方。 思路:简单的欧拉函数应用,由于T很大 先打表求前缀和 最后相减即可 初次接触欧拉函数 可以在素数筛选的写法上修改成欧拉函数。此外本题内存有限制 故直接计算平方值 #include <stdio.h> #include <iostream> #include <string.h> #include &lt...

weixin_30377461的博客 132

【LightOJ - 1007】Mathematically Hard 【欧拉函数筛】

Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable. In this problem, you will be given two integers a and b. You have to find the summatio...

lzs_lazy 205

LightOJ - 1007 Mathematically Hard 欧拉函数快速打表+前缀和

这个题 就是欧拉函数类筛法(素数的筛法打表)打表 开始各种 TLE, MLE 后来慢慢优化成 unsigned long long 后,因为输出错误还WA了一次 #include #include #include #include #include #include #include #include #include #include #include using namesp

床前明月光 366

LightOJ1007 Mathematically Hard(欧拉函数打表+前缀和(附:欧拉函数模板(2套)))

题目链接:https://cn.vjudge.net/contest/319236#problem/A Sample Input 3 6 6 8 8 2 20 Sample Output Case 1: 4 Case 2: 16 Case 3: 1237 给定一个区间,求区间内的每个数的欧拉函数的平方进行累加。 知识点: 求单个数的欧拉函数 欧拉函数的定义:phi(n)=n*(1-p1)*(1...

zaiyang遇见 282
上一篇: LightOJ1006---Hex-a-bonacci(矩阵快速幂)
下一篇: POJ1284---Primitive Roots(求原根个数, 欧拉函数)
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值