Uva--10820(数论,欧拉函数,筛法)

2014-09-03 00:58:22

原题题目老长,不多说了,小白书例题。

思路:1 <= x,y <= n,要求(x,y)的对数,所以x,y互质。不妨先设x > y,对于某个给定的x,(x,y)的对数就是其欧拉函数值。所以把1~n的所有欧拉函数值求出来 × 2就行了(因为先设定x>y,所以×2),最后要减去1(因为(1,1)算重了一次)

 1 /*************************************************************************
 2     > File Name: Uva10820.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com 
 5     > Created Time: Wed 03 Sep 2014 12:25:06 AM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <iostream>
13 #include <algorithm>
14 using namespace std;
15 typedef long long ll;
16 const int RA = 50000;
17 
18 int N;
19 int phi[RA + 5];
20 ll sum[RA + 5];
21 
22 void Phi_table(){
23     phi[1] = 1;
24     for(int i = 2; i <= RA; ++i) if(!phi[i])
25         for(int j = i; j <= RA; j += i){
26             if(!phi[j]) phi[j] = j;
27             phi[j] = phi[j] / i * (i - 1);
28         }
29 }
30 
31 void Pre(){
32     for(int i = 1; i <= RA; ++i)
33         sum[i] = sum[i - 1] + (ll)phi[i];
34 }
35 
36 int main(){
37     Phi_table();
38     Pre();
39     while(scanf("%d",&N) != EOF && N){
40         printf("%lld\n",sum[N] + sum[N] - 1);
41     }
42     return 0;
43 }

 

转载于:https://www.cnblogs.com/naturepengchen/articles/3952672.html

ESP-CSI:使用ESP32进行CSI(信道状态信息)采集 使用esp32进行csi(信道状态信息)采集和处理 阅读详情

相关推荐

Windows平台无人机仿真:从零搭建SITL环境与QGC联调

本文详细指导了在Windows平台上从零搭建无人机软件在环(SITL)仿真环境,并与QGroundControl(QGC)进行联调的完整流程。通过使用Cygwin工具链,开发者可以在没有实体硬件的情况下,模拟运行ArduPilot飞控,并通过MAVLink协议连接QGC地面站进行全功能测试,为无人机软件开发提供了一个安全、经济的虚拟沙盒环境。

weixin_29239279的博客 409

UVA - 10820 Send a Table(欧拉筛法)

题目链接  http://acm.hust.edu.cn/vjudge/problem/19595 题意:求1~n之间共有多少对互质的数。 用欧拉函数 (欧拉筛法)  复杂度 O(nloglogn)   在转化为有多少对时,(1,1)被算了两次,所以减去1次 #include #include #include #include #include #includ

Waves___的博客 509

RK3576+IMX415 MIPI摄像头零拷贝显示系统

MIPI CSI-2是嵌入式视觉系统中主流的高速图像传感器接口标准,其核心价值在于低延迟、高带宽与硬件级DMA直通能力。基于V4L2子系统与DRM/KMS驱动栈,可构建从传感器RAW数据到帧缓冲区的零拷贝通路,显著降低CPU负载并提升实时性。该技术广泛应用于工业检测、边缘AI推理前数据接入及多路同步采集等场景。本文以Rockchip RK3576 SoC和索尼IMX415传感器为典型组合,详解MIPI物理层适配、内核驱动集成、GStreamer零拷贝管道搭建及systemd服务化部署,覆盖从硬件信号完整性到

weixin_36047538的博客 217

UVA-10820(数论)(欧拉phi函数模板题)

题解:输入n,有多少个二元组(x,y)满足:1<=x,y<=n,且x,y互素。 欧拉phi函数模板题。 ans=2*f(n)+1,其中f(n)=phi(2)+phi(3)+…phi(n)。 附上AC代码 #include <bits/stdc++.h> #define FOPI freopen("INPUT.TXT", "r", stdin) #define DOPI fr...

白衣少年郎 456

TP4056在单节锂电池充电管理中的创新应用与电路优化

本文深入探讨了TP4056线性充电管理芯片在单节锂电池充电电路中的创新应用与优化方案。针对“边充边用”的核心挑战,文章详细解析了利用PMOS管构建智能供电切换电路的原理,实现了外部电源与电池供电的无缝、安全切换,有效杜绝了电池“边充边放”的风险。同时,提供了关键的元器件选型、PCB布局布线技巧及常见问题排查指南,为创客和硬件开发者提供了高性价比、高可靠性的锂电池电源管理实践方案。

rock5的博客 501

Zabbix-01简单导入MIB文件并测试

这里写自定义目录标题安装 MIB文件启用MIB文件测试MIB文件 MIB文件 MIB代表管理信息库。 MIB文件允许您使用OID(对象标识符)的文本表示。 ##例如: ifHCOutOctets 是OID【1.3.6.1.2.1.31.1.1.1.10】的文本表示 安装 MIB文件 在基于Debian的系统上: # apt install snmp-mibs-downloader # download-mibs 在基于RedHat的系统上: # yum install net-snmp-libs 启用M

lokibaba的博客 9178

UVA 10820 Send a Table (欧拉函数)

UVA 10820 Send a Table (欧拉函数) 输入n,对于整数x,y(1<=x,y<=n),f(x,y)=f(kx,ky),k式正整数。 所以可以用过f(x,y)的性质对函数表进行化简。问在[1,n]内最简的整数表有多少个元素。 问题的实质是求在[1,n]内有多少对互素的整数,因为如果x,y不互质,那必然存在因子k,满足f(x’,y’)=f(kx’,ky’)。 对于欧拉函数F,F(x)的值就表示小于n且与n互素的数的个数。 欧拉函数F的表达式可以由相容排斥原理得到,且可以化为下面的

WedsonLin的博客 223

基于PLC智能立体车库控制系统设计

摘要 本系统设计以三层立体车库为研究对象,通过对立体车库的原理分析、动作流程设计和一系列的软硬件设计,达到立体车库自动化控制的目的。系统采用可编程控制器作为立体车库控制系统的控制单元,实现该系统的工艺要求,通过程序仿真调试,完成系统的各种动作要求,达到自动控制的目的。系统设计分为总体设计、硬件设计以及软件设计。按照立体车库控制系统的控制策略进行图纸设计;重点分析工艺流程图,对立体车库控制系统进行程序编译和MCGS上位机调试,通过系统的调试和修改,达到了基本控制的要求。系统设计明确了工艺要求,确定

DX884164131的博客 3600

uva-10820-Send a Table 欧拉函数,筛法求欧拉函数

G - Send a Table Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 10820 Appoint description: Description Problem A Send a Table

qq_27295525的专栏 330

8.9华为OD机试真题 新系统 - 灯带颜色变换 (Java/Py/C/C++/Js/Go)

8.9华为OD机试真题 新系统 - 灯带颜色变换 (Java/Py/C/C++/Js/Go)

算法大师! 670

华为MetaERP月结加速方案:并行关账技术深度解析

【摘要】华为MetaERP并行关账技术通过创新架构设计,将传统串行月结流程(8-12小时)优化为并行执行(2-4小时)。关键技术包括:1)基于DAG引擎的任务依赖分析,实现模块/子任务三级并行;2)Saga模式分布式事务保障数据一致性;3)动态资源分配算法提升CPU利用率至60-80%。实施效果显示月结时间缩短70%,成功率提升至99.8%,错误恢复时间减少75%。该方案为大型企业ERP系统提供了高效的月结加速方案,未来还将结合AI调度与混合云扩展持续优化。

金牌架构师 1441

UVA10820SendATable

一道欧拉函数题。很好理解,就是不好往这个方向上想。看来还需要多做题。。。。

qq_16603365的博客 207

【项目实战】自动化测试软件VectorCAST介绍

VectorCAST是一款先进的自动化测试软件。VectorCAST是一款功能强大、易于使用的自动化测试软件。VectorCAST适用于各种嵌入式系统的测试。VectorCAST为嵌入式系统的测试提供了一种高效、可靠的解决方案。VectorCAST提供了一整套完整的测试工具,包括测试管理、代码覆盖、缺陷定位、报告生成等,以帮助开发人员提高测试效率,确保软件质量。VectorCAST支持。

奶爸的编程之路,也就一周冷个三天 2009

UVA 10820 Send a Table [欧拉函数] [线性筛法]

Send a Table 欧拉函数 线性筛法

C'est la vie. 477

IEM模型,地表粗糙度模拟

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

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

uva 10820

欧拉函数 #include #include #include #include #include #define maxn 50010 #define INF 0x7fffffff #define ull unsigned long long using namespace std; int prime[maxn]; int n; void init() { memset(

xlc2845的专栏 696

深度学习工具包 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")

UVA 10820 - Send a Table 数论 (欧拉函数)

Send a Table Input: Standard Input Output: Standard Output   When participating in programming contests, you sometimes face the following problem: You know how to calcutale the output for the give

LYHVOYAGE的专栏 2230

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

UVa 10820 - Send a Table

题目:找到整数区间[1,n]中多有的互质数对。 分析:数论,筛法,欧拉函数。在筛素数的的同时,直接更新每个数字的欧拉函数。             每个数字一定会被他前面的每个素数筛到,而欧拉函数的计算是n*π(1-1/pi);             其中,pi是n的素数因子,所以可以利用筛法来计算欧拉函数,然后求和;             注意,这时求出的欧拉函数为所有小于n的数m与

小白菜又菜 1275

uva 10820 (筛法构造欧拉函数)

sendatable When participating in programming contests, you sometimes face the following problem: You knowhow to calcutale the output for the given input values, but your ...

Dara2015的博客 172

UVa 10820 - Send a Table 欧拉函数模板

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=115&problem=1761&mosmsg=Submission+received+with+ID+13729379

u014683696的专栏 418

紫书 例题 10-7 UVa10820 欧拉函数

题意:求1~n之间共有多少对互质的数 分析:如果用普通方法一个一个判断,时间复杂度是O(n^2),会超时。但是可以利用欧拉函数和筛法在O(nloglogn)时间内把50000内与每个数互质的正整数的个数求出来。当求有多少对时,只需令sum[n]*2 —1即可。 解题方法:// //Created by BLUEBUFF 2016/1/11 //Copyright (c) 2016 BLUEBUF

I good vegetable a! 698

UVA10820 send a table

题意:对(x,y),1<=x,y<=n 求出有多少对(x,y)互质 题解:筛法跑一遍欧拉就好了 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef l...

diaoqi6581的博客 135

Send a Table uva10820

题意: 求区间[1-n]的所有互质的对的对数,其中(2,3)与(3,2)记为两对 思路: 筛法求救欧拉函数 求出y以前与其互斥的x,用p记录 对于求n以前与其互斥的数的个数,有函数n/i*(i-1)/j(j-1)...其中i, j为组成n的质因子 代码: #include #include #include const int maxn = 50000; int p[maxn

deepquiet的博客 362

uva 10820 紫书欧拉函数题目

#include #include #include using namespace std; const int maxn=50000+5; int phi[maxn]; void phi_table(int n,int* phi) {     memset(phi,0,sizeof(phi));     phi[1]=1;     for(int i=2; i  

qq_36289725的博客 252
上一篇: Uva--1635(数论,组合数,唯一分解)
下一篇: Uva--1262(数学,排列)
dingdi3021
博客等级 码龄11年 1粉丝 230原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值