LightOJ1007 Mathematically Hard 欧拉函数+前缀和

欧拉函数前缀和 首先在这里说声抱歉 我的上一篇欧拉函数的代码有一个小漏洞: 上一篇的链接 //这里先乘后除乘的时候可能会造成数据溢出 res = res * (i - 1) / i; //所以这个操作要先除后乘 res = res / i * (i - 1); //这个也同理 res = res * (n - 1) / n; 好了现在开始正题 有些题需要我们求φ(1)+φ(2)+φ(3)+…+φ(N) 显然这时... 阅读详情

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 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

3

6 6

8 8

2 20

Sample Output

Case 1: 4

Case 2: 16

Case 3: 1237

Hint

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




#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define INF 0x3f3f3f3f
typedef unsigned long long LL;
#define maxn 5000000
LL euler[maxn+5];
void euler_init(){
    for(int i=0;i<=maxn;i++){
        euler[i]=i;
    }
    for(int i=2;i<=maxn;i++){
        if(euler[i]==i){
            for(int j=i;j<=maxn;j+=i){
                euler[j]=euler[j]/i*(i-1);
            }
        }
    }
    for(int i=2;i<=maxn;i++){
        euler[i]=euler[i-1]+euler[i]*euler[i];
    }
}

int main()
{std :: ios :: sync_with_stdio (false);
    int t,a,b,ca=1;
    scanf("%d",&t);
    euler_init();
    while(t--){
        scanf("%d%d",&a,&b);
        printf("Case %d: %llu\n",ca++,euler[b]-euler[a-1]);
    }
    return 0;
}


均匀直线阵的常规波束形成matlab 常规波束形成概述 波束形成是将基阵各阵元输出进行一定的处理,从而形成基阵空间指向性的技术。一个波束形成器可以对空间某方位的信号有响应,而抑制其他方位的信号,所以又被称为空域滤波。一般分为常规波束形成(CBF)和自适应波束形成(ABF)。 常规波束形成较为基础,一般又可以根据实现的途径不同,分为时延波束形成和频移波束形成。 时延波束形成 在各阵元间添加时延使波束控制于不同方位的方法成为时延波束形成。设定一个目标方向,当信号来源方向在该目标方向时,响应最大;信号来源于其他方向时,响应较小。将这种响应大小 阅读详情

相关推荐

TortoiseGit之配置密钥

基于github的开发必须要用到rsa密钥,因此需要用到TortoiseGit的putty key generator工具,来生成既适用于github的rsa密钥也适用于TortoiseGit的ppk密钥。

欧文的博客 2109

POJ2478 Farey Sequence【欧拉函数+前缀和】

POJ2478 Farey Sequence 题目 函数F(n)定义为最简分数 a/b 的个数,其中n>1,0<a<b<=n,求F(n)的值 输入 正整数n,n=0时结束 输出 F(n) 样例输入 2 3 4 5 0 样例输出 1 3 5 9 分析 当a和b互质时a/b为最简分数,设f(n)表示为小于n且与n互质的数的个数,那么易得F(n...

逐梦者 403

FPGA实战:手把手教你用Verilog驱动4.3寸RGB触摸屏(附完整代码)

本文详细介绍了如何使用Verilog语言在FPGA上驱动4.3寸RGB触摸屏,包括时序设计、信号交互原理及完整代码实现。通过双计数器引擎设计和参数化模块,开发者可以高效构建800*480分辨率的显示驱动,并解决工程实践中的信号完整性和时序收敛问题。

rice5的博客 713

分子个数 数论(欧拉函数 前缀和

欧拉函数

Rachelhello123的博客 343

ANSYS APDL生死单元实战:焊接模拟从入门到精通(附完整命令流)

本文详细介绍了使用ANSYS APDL进行焊接模拟的核心技术——生死单元法。通过一个完整的平板对接焊案例,从原理剖析、模型搭建、命令流编写到移动热源施加和后处理,手把手指导工程师掌握这一动态仿真方法,有效预测焊接过程中的温度场、残余应力与变形。

k6l7m8n9的博客 162

2022(一等奖)B360基于Arcpy与SVM的滑坡易发性评价

此外,在ArcGIS平台下,“易发性图预测(多进程)”工具的运行时间为2h 48m 3s,“易发性图预测(单进程)”工具的运行时间为5h 19m 27s,运行时间缩短了近2h 31m 24s,运行效率提高了47.39%。在ArcGIS Pro平台下,“易发性图预测(多进程)”工具的运行时间为20m 12s,“易发性图预测(单进程)”工具的运行时间为1h 26m 47s,将运行时间缩短了近1h 6m 35s,运行效率提高了76.72%。滑坡的发生受各种影响因素的影响,目前,影响因素的选择没有一个统一的标准。

2301_77310370的博客 1481

基础数论(Farey Sequence)(欧拉函数,欧拉线性筛,前缀和)

Farey Sequence 众所周知,小涛涛学长是数论的king,artist今天去请教了他一个问题,小涛涛学长读完题目后,觉得太简单了,对artist十分失望,随即离开,只留下一个背影,artist向你求助,你能帮帮她吗? 有一个数列叫做dxl数列,对任意n,DXLn代表一个包含不可简化(不可约分)的有理分数a/b的序列,满足0 < a < b <= n且gcd(a,b)=1,序列中的分数按照递增顺序排列。 前几个DXLn为: DXL2 = {1/2} DXL3 = {1/3, 1/2

weixin_51979465的博客 445

MoveIt 运动学、运动规划、混合规划、move_group

混合规划是运动规划方法的一个术语,它将异构运动规划器结合起来,以产生更稳健或反应更快的解决方案。这种通用方法在导航领域已经非常成熟,并在导航2等流行项目中成功实施。MoveIt 的混合规划架构结合了一对全局规划器和局部规划器,它们以不同的规划速度和问题范围并行、并发运行。全局规划器的任务是解决全局运动规划问题,这与 “感知-规划-行动 ”应用中使用的规划器非常相似。所使用的规划器算法应该是完整的,因此假定其计算时间相对较慢。此外,全局规划器不要求实时安全,这意味着无法保证规划器在特定期限内找到解决方案。

机器人控制与仿真应用 2145

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遇见 284

软考中级-软件设计师 知识点整理(一篇就过了 建议收藏)

软考中级-软件设计师上午题知识点总结

片言可决讼,半纸能缚龙 18万+

手把手教你学Simulink--基于Simulink的开关磁阻电机电流斩波控制仿真建模

特点:定子和转子均由普通硅钢片叠压而成,没有永磁体或绕组在转子上。工作原理:利用转子旋转时不同位置的磁阻变化产生转矩。控制挑战:由于SRM的高度非线性和磁饱和效应,需要复杂的控制算法来优化性能。利用Simscape Electrical中的模块构建SRM的物理模型,配置参数如电阻、电感等。matlab深色版本% 添加SRM电机模块根据实际需求调整电机参数。通过上述步骤,我们简要介绍了如何基于Simulink进行开关磁阻电机的电流斩波控制仿真建模。

MHD0815的博客 314

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

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

床前明月光 366

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Mathematically Hard LightOJ - 1007

Mathematically Hard LightOJ - 1007  题意:求出m到n之间的,每个数与他互质的数的个数的平方和。 比如 6之前的与他互质的有 2个 那么 结果就是 4 5 6 就是 5 之前的与他互质的有 4个 6 有2个 结果为 4*4+2*2;   思路 :欧拉函数求出每个数之前与他互质的数的个数,然后预处理求前缀和  爆long long 注意 要 开 usiga...

qq_41650771的博客 220

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

LightOJ 1007 - Mathematically Hard (欧拉筛+预处理前缀和)

1007 - Mathematically Hard   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 64 MB Mathematically some problems look hard. But

滴水穿石,慢慢积累,总会有成果 851

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

light oj 1007 Mathematically Hard (欧拉函数)

题目地址:light oj 1007 第一发欧拉函数。 欧拉函数重要性质: 设a为N的质因数。若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N / a) * a;若(N % a == 0 && (N / ...

aoe41606的博客 138

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

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 to find the summation o

Alex 1614

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 integersaandb. You have to find the summatio...

Vace___yun的博客 236

LightOJ 1007 Mathematically Hard

第一次到LightOJ做题,输入输出好不习惯,不过题目描述比Poj清楚多了。 题目链接 http://lightoj.com/volume_showproblem.php?problem=1007 题意:计算所给出的a,b两数间(包括a,b)的所有数的欧拉函数的平方和。 思路:利用前缀和优化减少运算时间,需要用unsigned long long才能存下数据。

whyorwhnt的专栏 1190

LightOJ1007 Mathematically Hard

LightOJ1007 题目的意思很容易理解,求一个区间[a,b]内的欧拉函数平方之和 但是题目的数据限很大 a,b都是1e12级。按照一般思路写好程序后,实验以下从2到10000发现long long也会超范围,所以用unsigned long long。 此外还需要预处理前缀和,不然就会超时。 预处理前缀和时不能够再开数组,不然就会爆内存,WA点多多. AC代码:#include <b

风城 444

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。。。

弱智就要多努力 446

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 =

裤头是叫裤头的裤头 339

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

冷月之殇 1273
上一篇: CodeForces711E ZS and The Birthday Paradox 费马小定理求逆元
下一篇: LightOJ1215 Finding LCM
Megumin
博客等级 码龄10年 3粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址