uva10820 - Send a Table 欧拉函数

Materials Studio与LAMMPS联合作战:如何用msi2lmp.exe完美转换聚合物模型(含PCFF力场配置) 本文详细解析了如何利用msi2lmp.exe工具将Materials Studio中的聚合物模型高效、准确地转换为LAMMPS可识别的data文件,并重点配置PCFF力场。文章提供了从MS模型构建、文件导出到命令行转换、参数调整及转换后验证的全流程实战指南与避坑技巧,旨在帮助研究者解决模型转换中的常见问题,实现跨平台分子动力学模拟的无缝衔接。 阅读详情

Problem A
Send a Table
Input:
Standard Input

Output: Standard Output

 

When participating inprogramming contests, you sometimes face the following problem: You know how tocalcutale the output for the given input values, but your algorithm is way tooslow to ever pass the time limit. However hard you try, you just can't discoverthe proper break-off conditions that would bring down the number of iterationsto within acceptable limits.

Now if the range of input values is not too big,there is a way out of this. Let your PC rattle for half an our and produce atable of answers for all possible input values, encode this table into aprogram, submit it to the judge, et voila: Accepted in 0.000 seconds! (Somewould argue that this is cheating, but remember: In love and programmingcontests everything is permitted).

Faced with this problem during one programmingcontest, Jimmy decided to apply such a 'technique'. But however hard he tried,he wasn't able to squeeze all his pre-calculated values into a program smallenough to pass the judge. The situation looked hopeless, until he discoveredthe following property regarding the answers: the answers where calculated fromtwo integers, but whenever the two input values had a common factor, the answercould be easily derived from the answer for which the input values were dividedby that factor. To put it in other words:

Say Jimmy had to calculate a function Answer(x,y) where x and y are both integers in the range [1, N].  When he knows Answer(x, y), he can easilyderive Answer(k*x, k*y), where k is any integer from it by applying some simplecalculations involving Answer(x, y) and k. For example if N=4, he only needs toknow the answers for 11 out of the 16 possible input value combinations:Answer(1, 1), Answer(1, 2), Answer(2, 1), Answer(1, 3), Answer(2, 3), Answer(3,2), Answer(3, 1), Answer(1, 4), Answer(3, 4), Answer(4, 3) and Answer(4, 1).The other 5 can be derived from them (Answer(2, 2), Answer(3, 3) and Answer(4,4) from Answer(1, 1), Answer(2, 4) from Answer(1, 2), and Answer(4, 2) fromAnswer(2, 1)). Note that the function Answer is not symmetric, so Answer(3, 2)can not be derived from Answer(2, 3).

Now what we want you to do is: for any values ofN from 1 upto and including 50000, give the number of function Jimmy has topre-calculate.

Input
The input file contains at most 600 lines ofinputs. Each line contains an integer less than 50001 which indicates the valueof N. Input is terminated by a line which contains a zero. This line should notbe processed.

 

Output

For eachline of input produce one line of output. This line contains an integer  which indicates how many values Jimmy has topre-calculate for a certain value of N.

 

 

 

 

SampleInput                              Output for Sample Input

2

5

0

 

3

19

 



  φ函数的值  通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是不为0的整数。φ(1)=1(唯一和1互质的数(小于等于1)就是1本身)。 (注意:每种质因数只一个。比如12=2*2*3。
若n是质数p的k次幂,φ(n)=p^k-p^(k-1)=(p-1)p^(k-1),因为除了p的倍数外,其他数都跟n互质。
设n为正整数,以 φ(n)表示不超过n且与n互
素的正整数的个数,称为n的欧拉函数值,这里函数
φ:N→N,n→φ(n)称为欧拉函数。
若m,n互质,φ(mn)=φ(m)φ(n)。
特殊性质:当n为奇数时,φ(2n)=φ(n)。

  以上这一段来自百度百科。

  打出欧拉公式的表也就比快速打素数表多出一步,找到素数p后把这个素数的倍数x都标记(如果x没有访问过,就先把phi[x]赋值为x),由于x有素因子p,所以要乘以(1-1/p),也就是除以p再乘(p-1)(注意最好是先除再乘,防止越界)。最后把小于等于要求值的素数都找一遍后,每个φ(x)就都求出来了。

  这道题求的是小于等于N的互素对数,所以打完表后要递推一下,phi[i]=phi[i-1]+phi[i],再就是一组两个数交换位置也算,所以答案要乘以2,(1,1)是特例,要再减去1。
 
 
#include<cstring>
#include<cstdio>
#include<iostream>
#include<climits>
#include<cmath>
#include<algorithm>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
int N,phi[50010],M=50010;
void phi_table(){
    memset(phi,0,sizeof(phi));
    int i,j;
    phi[1]=1;
    for(i=2;i<=M;i++) if(!phi[i]){
        for(j=i;j<=M;j+=i){
            if(!phi[j]) phi[j]=j;
            phi[j]=phi[j]/i*(i-1);
        }
    }
}
int main(){
    //freopen("in.txt","r",stdin);
    phi_table();
    int i;
    for(i=2;i<=M;i++) phi[i]=phi[i]+phi[i-1];
    while(scanf("%d",&N),N){
        printf("%d\n",phi[N]*2-1);
    }
    return 0;
}



爬取二手房数据:Python爬虫+Geopy实战,看透房价与地理位置的隐藏关系 哪些区域单价虚高(房源少但单价远高于周边);哪些小区性价比高(靠近地铁/学校,单价低于同地段平均水平);房价与地理位置的量化关系(如距离地铁每远1公里,单价下降多少)。如果想扩展分析范围,可爬取多个城市/区域的数据,对比不同城市的房价差异;或结合时间维度(定期爬取),分析房价的涨跌趋势。 阅读详情

相关推荐

Mac OS X 工具技巧:一文搞定个性化命令行窗口(iTerm2 + zsh + oh-my-zsh 配置Powerline风格)

本不想写这篇文章的,因为在Linux下已经配置过很多次,想着mac应该找篇文章一次就搞定了,结果还是踩坑,看了很多文章,不是某一点没不清楚,就是截图有问题或者命令有问题,官网又难得找等等……花了3个多小时才搞定,所以,还是来总结一篇文章就能够搞定的教程。 为什么要用zsh?用了这么多年的bash,不能说bash不好,不过当我用了zsh后发现,什么叫更好用。 配置过程稍微有点繁琐,但是你看过效果...

mickjoust的技术小屋 1万+

UVaOJ10820 - Send a Table

Problem A 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 f

c随遇er安的专栏 816

Unity 多线程编程笔记 _Task详解

士大夫

weixin_43405845的博客 4390

UVA_10820_send a table

When participating in programming contests, you sometimes face the following problem: You know how to calcutale the output for the given input values, but your algorithm is way too slow to ever p...

awang50683的博客 149

保姆级教程:手把手教你从ENSEMBL官网下载GRCh38/GRCh37的GTF注释文件(附网址规律总结)

本文提供从ENSEMBL官网下载GRCh38/GRCh37的GTF注释文件的详细教程,包括路径解析、版本号确定和下载命令示例。特别解析了GRCh37的特殊存储结构,并分享批量下载、文件校验等高级技巧,帮助生物信息学研究者高效获取基因组注释文件。

weixin_29289821的博客 208

内核工作FAST‘25 Artifact Evaluation流程记录

在我们的paper中,复现需要用到傲腾持久化内存,因此,需要AE Reviewer访问到内网服务器中。我们的思路是购买云服务器,将其作为跳板机,内网服务器通过SSH反向代理与公网服务器建立隧道,AE Reviewer通过隧道访问内网服务器。我们在AE过程中使用。然后,把一切复现需要的代码环境,在chroot里面配置完成。

不定期更新系统使用、编程小技巧,哔哩哔哩账号:https://space.bilibili.com/399455629,欢迎关注 1219

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

原题: When participating in programming contests, you sometimes face the following problem: You know how to calcutale the output for the given input values, but your algorithm is way to o slow to

Lllll_sh的博客 323

非球面检测

摘要:非球面镜检测主要采用干涉法,包括零位补偿和非零位补偿两种方式。零位补偿通过透镜组完全校正像差,精度达1%波长,但设计复杂成本高;非零位补偿利用部分像差补偿降低波前斜率,适用于规则非球面。折射-衍射混合补偿镜能同时校正多种像差。实际检测中可采用物理补偿镜或动态CGH加载方案,光路设计需运用坐标断点和多重结构技术实现复杂光路建模。不同方法各具优势,需根据检测需求选择合适方案。

Zhaxibamao的博客 2124

数论:欧拉函数 uva 10820

10820 - Send a Table Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1761 When participating in programmin

Dikea's Blog 1003

CANOe实战指南 - 从入门到精通的全流程解析

本文是CANOe实战指南,全面解析从入门到精通的全流程。内容涵盖CANOe软件的核心功能仿真、测试与分析,详细指导安装配置、工程创建、CAN信号收发、UDS诊断通信、CAPL自动化编程以及Panel面板设计。通过实战案例,帮助汽车电子工程师快速掌握这一行业标杆工具,构建自动化测试环境,提升开发与测试效率。

pear55的博客 587

Oracle11g下载与安装(windows)

一、Oracle11g下载 二、安装准备 三、执行安装步骤 四、测试连接 附:Oracle11g服务说明

欢迎订阅我的“JAVA全栈开发笔记(全)”专栏,价格优惠,仅需19.9元。 2万+

UVA 10820 Send a Table(欧拉函数)

题目链接: UVA 10820 Send a Table欧拉函数。#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <climits> #include <cmath> #include <ctime> #include <cassert>

ramay7 711

上线之前多一道闸:业务审核系统的接入定义、双轨状态机与可靠生效闭环

运营后台“保存即生效”,让价格、库存、人群等配置每次修改都相当于一次无评审的上线。本文以至尊会员降价活动为例,系统拆解业务审核系统:用带业务语义的操作编码、规则化审核人与候选人快照、完整的生效回调契约做好接入定义;把业务改造为提交待生效,以不可变快照、字段级差异和唯一约束加幂等号防误配防重复;用审批轨与执行轨双轨状态机、链路式重新提交和以事件为准的审核链路理清状态;最后以发件箱、幂等键、超时先查后试、乐观锁与对账闭合生效环节,并结合两个可运行的Java程序,给出五种生效策略的事故率实测对比。

曾经“等你生日那天”都遥远得像未来,如今却可欢愉的挥手说“下个十年见” 6万+

[UVA 10820]Send a Table[欧拉函数][nloglog(n)]

题目链接:[UVA 10820]Send a Table[欧拉函数][nloglog(n)] 题意分析: 友人A想要打表过题,每个表内数据都是以数对的形式(x,y)出现,但是呢,表太大了,OJ不让上交。机智的他发现了一个规律:数对(x*k, y*k)可以由数对(x,y)推出来,所以他只用打(x,y)上交就行了。比如(1,2)被打入表,那么(2,4) (3,6)....这些数据就不用打入表了。现

闲停 1011

lwip-2.0.3

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

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

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的博客 224

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

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

题目传送:UVA - 10820 思路:找出1~n之间的所有互质的整数对,可以用欧拉函数做,先打出50000以内的欧拉函数的表,然后累加即可 AC代码: #include #include #include #include #include #include #include #include #include #include #include #i

Never say never 755

uva 10820 - Send a Table(欧拉函数)

题目链接:uva 10820 - Send a Table 题目大意:给出一个n,求从1~n中任意两个数互质的对数为多少,和算两对。 解题思路:白书上介绍用nloglogn的算法构造欧拉函数,然后用一个sum数组储存下总值,因为和算两对,所以每个phi[i]要加两倍,特殊情况用初始化sum[1] = 1. #include #include const int

不慌不忙、不急不躁 1374

UVA10820 Send a Table【欧拉函数打表】

When participating in programming contests, you sometimes face the following problem: You know how to calcutale the output for the given input values, but your algorithm is way too slow to ever pass the time limit. However hard you try, you just can’t disc

海岛Blog 484

UVa 10820 Send a Table(欧拉函数)

题目链接:UVa 10820 - Send a Table 欧拉函数。

fobdddf的专栏 762

UVA.10820 Send A Table (欧拉函数)

UVA.10820 Send A Table (欧拉函数)标签(空格分隔): 数论题意分析题面说的比较花里胡哨,最总要的是发现,需要打得的表的数字(x,y)(x,y)满足gcd(x,y)=1gcd(x,y) = 1,也就是说x,yx,y互质。发现这个性质之后,就不是很难了。 规定x<yx<y,可以将规模缩减一半,最后输出只需要乘2就好了,对于x=yx=y的情况,发现只需要(1,1)(1,1),故乘

Pengwill's Blog 217

UVa 10820 Send a Table (欧拉函数)

题目 题目大意 有一道比赛题目, 输入两个整数\(x\)、\(y\)(\(1 ≤ x, y ≤ n\)), 输出某个函数\(f(x, y)\)。有位选手想交表(即事先计算出所有的\(f(x, y)\), 写在源代码里), 但是表太大了, 源代码超过了比赛的限制, 需要精简。 好在那一道题目有一个性质, 使得很容易根据\(f(x, y)\)算出\(f(xk, yk)\)(其中\(k\)是任...

aa445354403的专栏 139

UVA 10820 Send a Table——欧拉函数

欧拉函数模板题不难发现除了(1,1)之外,其余二元组中两个元素均不相等。设满足x&lt;y的二元组有ans个,那么结果就是ans*2+1;根据欧拉函数的定义,易知ans=phi(2)+phi(3)+、、、+phi(n)#include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;iostream&gt; #include &lt;alg...

hao_zong_yin的博客 358

UVA 10820 Send a Table 数论 欧拉函数

  题目链接:https://vjudge.net/problem/UVA-10820   题目描述: 给你一个N, N <= 50000, 让你寻找N之内互素数的个数   解题思路: 欧拉函数, 由于位置颠倒是两个解, 在小于N的范围内只有(1, 1)x, y相等, 其他的都是不等的, 所以我们只需要算phi(2) + phi(3) + ...... phi(n), 然后 * 2 +...

weixin_34336292的博客 122

Send a Table UVA - 10820(思维+欧拉函数)

Send a Table UVA - 10820 题意: 给你n*n个二元组,要求你统计要预先算出多少个(x,y)。(其中(kx,ky)可以通过(x,y)推出来)。 思路: 本质: 输入n,有多少个二元组(x,y)满足:1<=x,y<=y,且x和y互素。不难发现除了(1,1)之外,其他满足条件的二元组(x,y)中的x和y都不相等。假设满足x<y的二元组有f(n)个,那么ans = 2*f(n)+1。 根据欧拉函数的定义 f(n)=phi(2)+phi(3)+...+phi(n)f(n)

qq_45377553的博客 153

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

题目链接 https://cn.vjudge.net/problem/UVA-10820 【题意】 输入n(n<=50000),求出有多少个二元组(x,y)满足1<=x,y<=n 且x,y互素 【思路】 在符合要求的二元组中,除了(1,1)之外其它的(x,y)中的x和y都不想等,假设满足x < y的二元组有f[n]个,...

weixin_30772105的博客 124

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
上一篇: uva106 - Fermat vs. Pythagoras 互素勾股数
下一篇: uva11029 - Leading and Trailing n^k保留前三位
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值