sgu 102模拟欧拉函数
感觉自己弱爆了,做做SGU吧。。。
#include<iostream>
#include<cmath> //欧拉函数
using namespace std;
int euler(int n)
{
int m=n; int ans=n;
for(int i=2;i<=sqrt(n*1.0);i++) //注意等于号,
{
if(m%i==0)
{
ans=ans*(i-1)*1.0/i;
while(m%i==0)m/=i;
}
}
if(m!=1)ans=ans*(m-1)/m;
return ans;
}
int main()
{
int n;
while(cin>>n)
{
cout<<euler(n)<<endl;
}
}
sgu 102模拟欧拉函数的更多相关文章
- NOIP模拟:切蛋糕(数学欧拉函数)
题目描述 BG 有一块细长的蛋糕,长度为 n. 有一些人要来 BG 家里吃蛋糕, BG 把蛋糕切成了若干块(整数长度),然后分给这些人. 为了公平,每个人得到的蛋糕长度和必须相等,且必须是连续的一段 ...
- poj2478 Farey Sequence (欧拉函数)
Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler( ...
- UVA12493 - Stars(求1-N与N互质的个数)欧拉函数
Sample Input 3 4 5 18 36 360 2147483647 Sample Output 1 1 2 3 6 48 1073741823 题目链接:https://uva.onlin ...
- 快速切题 sgu102.Coprimes 欧拉函数 模板程度 难度:0
102. Coprimes time limit per test: 0.25 sec. memory limit per test: 4096 KB For given integer N (1&l ...
- hdu2588 GCD (欧拉函数)
GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数. (文末有题) 知 ...
- BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2553 Solved: 1565[Submit][ ...
- BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4436 Solved: 1957[Submit][Status][Discuss ...
- COGS2531. [HZOI 2016]函数的美 打表+欧拉函数
题目:http://cogs.pw/cogs/problem/problem.php?pid=2533 这道题考察打表观察规律. 发现对f的定义实际是递归式的 f(n,k) = f(0,f(n-1,k ...
- 51Nod-1136 欧拉函数
51Nod: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1136 1136 欧拉函数 基准时间限制:1 秒 空间限制: ...
随机推荐
- c++ 各种类型字符串转换
typedef std::string u8string; u8string To_UTF8(const std::u16string &s) { std::wstring_convert&l ...
- Gersgorin 圆盘
将学习到什么 好多. Gersgorin 圆盘定理 对任何 \(A \in M_n\),我们总可以记 \(A=D+B\),其中 \(D=\mathrm{diag}(a_{11},\cdots, ...
- metasploit-shellcode生成
0x00 安装metasploit $ curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/t ...
- PAT (Advanced Level) Practise - 1096. Consecutive Factors (20)
http://www.patest.cn/contests/pat-a-practise/1096 Among all the factors of a positive integer N, the ...
- fckeditor配置详解
使用配置设置: . FCKConfig.CustomConfigurationsPath = '' ; // 自定义配置文件路径和名称 . FCKConfigFCKConfig.EditorAreaC ...
- 【图论 搜索】bzoj1064: [Noi2008]假面舞会
做到最后发现还是读题比赛:不过还是很好的图论题的 Description 一年一度的假面舞会又开始了,栋栋也兴致勃勃的参加了今年的舞会.今年的面具都是主办方特别定制的.每个参加舞会的人都可以在入场时选 ...
- 【Java_基础】Java中Native关键字的作用
本篇博文转载与:Java中Native关键字的作用
- SpringAOP拦截器的代理机制
要使用方法名匹配AOP切面编程,需要使用到spring中的org.springframework.aop.support.NameMatchMethodPointcutAdvisor这个类,advic ...
- 怎么用js写一个类似于百度输入框的搜索插件
PS:这次做的这个小插件只是在前端实现,并没有经过数据库.需要用到的的框架:1.bootstrap.css的样式 2.Vue.js 最终效果如下: JS部分: $(window).click(func ...
- 条款52:写了placement new 也要写placement delete(write placement delete if you write placement new)
NOTE: 1.当你写一个placement operator new .请确定也要写出了对应的placement operator delete.如果没有这样做,你的程序可能发生隐晦而时断时续的内存 ...