UVA 10820 欧拉函数模板题
这道题就是一道简单的欧拉函数模板题,需要注意的是,当(1,1)时只有一个,其他的都有一对。应该对欧拉函数做预处理,显然不会超时。
- #include<iostream>
- #include<string.h>
- #include<algorithm>
- #include<stdio.h>
- using namespace std;
- const int maxx = ;//最大范围
- int phi[maxx];
- void phi_table(){
- for(int i=;i<=maxx;i++)phi[i]=;
- phi[]=;
- for (int i=;i<=maxx;i++){
- if (!phi[i]){
- for (int j=i;j<=maxx;j+=i){
- if (!phi[j])phi[j]=j;
- phi[j] = phi[j] / i *(i-);
- }
- }
- }
- for (int i=;i<=maxx;i++){
- phi[i]+=phi[i-];
- }
- }
- int main(){
- int a;
- int n;
- phi_table();
- while(~scanf("%d",&n)){
- if (n==)break;
- int ans=*phi[n]-;
- printf("%d\n",ans);
- }
- return ;
- }
UVA 10820 欧拉函数模板题的更多相关文章
- (hdu step 7.2.1)The Euler function(欧拉函数模板题——求phi[a]到phi[b]的和)
题目: The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- poj2407(欧拉函数模板题)
题目链接:https://vjudge.net/problem/POJ-2407 题意:给出n,求0..n-1中与n互质的数的个数. 思路:欧拉函数板子题,先根据唯一分解定理求出n的所有质因数p1,p ...
- 数论 - 欧拉函数模板题 --- poj 2407 : Relatives
Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11372 Accepted: 5544 Descri ...
- XDU 1098 (欧拉函数模板题)
原题链接,点击此处 欧拉函数:φ(N)表示对一个正整数N,欧拉函数是小于N且与N互质的数的个数 通式:φ(x) = x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/p ...
- 找新朋友 HDU - 1286 欧拉函数模板题
题意: 求出来区间[1,n]内与n互质的数的数量 题解: 典型的欧拉函数应用,具体见这里:Relatives POJ - 2407 欧拉函数 代码: 1 #include<stdio.h> ...
- Trees in a Wood UVA - 10214 欧拉函数模板
太坑惹,,,没用longlong各种WA #include <iostream> #include <string.h> #include <cstdio> #in ...
- POJ 2407:Relatives(欧拉函数模板)
Relatives AC代码 Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16186 Accept ...
- POJ 2407 Relatives(欧拉函数入门题)
Relatives Given n, a positive integer, how many positive integers less than n are relatively prime t ...
- hdu 1286 找新朋友 欧拉函数模版题
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Des ...
随机推荐
- HBase快速安装
配置hbase-env.sh #JAVA_HOME 需要Java 1.7+ export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/ # Java CLA ...
- [20181130]control file sequential read.txt
[20181130]control file sequential read.txt --//昨天上午探究了大量控制文件读的情况,链接:http://blog.itpub.net/267265/vie ...
- mssql sqlserver 模拟for循环的写法
转自:http://www.maomao365.com/?p=6567 摘要: 下文讲述sql脚本模拟for循环的写法,如下所示: /* for样例 for('初始值','条件','执行后自增') 通 ...
- 【MM系列】SAP MM 非限制/可用库存
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MM 非限制/可用库存 ...
- php伪协议,利用文件包含漏洞
php支持多种封装协议,这些协议常被CTF出题中与文件包含漏洞结合,这里做个小总结.实验用的是DVWA平台,low级别,phpstudy中的设置为5.4.45版本, 设置allow_url_fopen ...
- LeetCode算法题-Fizz Buzz(Java实现)
这是悦乐书的第221次更新,第233篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第88题(顺位题号是412). 编写一个程序,输出从1到n的数字的字符串表示.但对于三的 ...
- June 2. 2018 Week 22nd Saturday
Try not to become a man of success but rather try to become a man of value. 不要为成功而努力,要为做一个有价值的人而努力. ...
- 自定义实现HashMap的put、get方法
public class HashMap{ public static void main(String[] args){ put("aa", "wo ai ni&quo ...
- Beta阶段 - 博客链接合集
Beta阶段 - 博客链接合集 项目Github地址 安卓端(Stardust):https://github.com/StardustProject/Stardust 服务器端(Gravel):ht ...
- [福大软工] Z班 团队Beta阶段成绩汇总
Beta敏捷冲刺得分 队伍名 1 2 3 4 5 总分 Dipper 10 10 10 10 10 50 SWSD 9 9 9 9 7 43 五成胜算 10 10 10 10 10 50 人月神教 0 ...