poj 2407 Relatives(简单欧拉函数)
Description
Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > , y > , z > such that a = xy and b = xz.
Input
There are several test cases. For each test case, standard input contains a line with n <= ,,,. A line containing follows the last case.
Output
For each test case there should be single line of output answering the question posed above.
Sample Input
Sample Output
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define ll long long
ll eular(ll n){
ll ans=;
for(ll i=;i*i<=n;i++){
if(n%i==){
ans*=i-,n/=i;
while(n%i==){
ans*=i;
n/=i;
}
}
}
if(n>) ans*=n-;
return ans;
}
int main()
{
ll n;
while(scanf("%I64d",&n)==){
if(n==) break;
ll ans=eular(n);
printf("%I64d\n",ans);
}
return ;
}
poj 2407 Relatives(简单欧拉函数)的更多相关文章
- POJ 2407 Relatives(欧拉函数)
http://poj.org/problem?id=2407 题意: 给出一个n,求小于等于的n的数中与n互质的数有几个. 思路: 欧拉函数的作用就是用来求这个的. #include<iostr ...
- POJ 2407 Relatives(欧拉函数入门题)
Relatives Given n, a positive integer, how many positive integers less than n are relatively prime t ...
- POJ 2407 Relatives 【欧拉函数】
裸欧拉函数. #include<stdio.h> #include<string.h> ; int p[N],pr[N],cnt; void init(){ ;i<N;i ...
- POJ 2407 Relatives (欧拉函数)
题目链接 Description Given n, a positive integer, how many positive integers less than n are relatively ...
- POJ 2407 Relatives【欧拉函数】
<题目链接> 题目大意: Given n, a positive integer, how many positive integers less than n are relativel ...
- POJ 2407:Relatives(欧拉函数模板)
Relatives AC代码 Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16186 Accept ...
- poj 2478 Farey Sequence(欧拉函数是基于寻求筛法素数)
http://poj.org/problem?id=2478 求欧拉函数的模板. 初涉欧拉函数,先学一学它主要的性质. 1.欧拉函数是求小于n且和n互质(包含1)的正整数的个数. 记为φ(n). 2. ...
- HDU 2824 简单欧拉函数
1.HDU 2824 The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a ...
- POJ2407 Relatives(欧拉函数)
题目问有多少个小于n的正整数与n互质. 这个可以用容斥原理来解HDU4135.事实上这道题就是求欧拉函数$φ(n)$. $$φ(n)=n(1-1/p_1)(1-1/p_2)\dots(1-1/p_m) ...
- (Relax 数论1.8)POJ 1284 Primitive Roots(欧拉函数的应用: 以n为模的本原根的个数phi(n-1))
/* * POJ_2407.cpp * * Created on: 2013年11月19日 * Author: Administrator */ #include <iostream> # ...
随机推荐
- 使用GCM服务(Google Cloud Messaging)实现Android消息推送
最近在网上查了关于很多Android消息推送的资料,其中主要有四种方法. 1) 使用GCM服务(Google Cloud Messaging) 2) 使用XMPP协议(Openfire + Spark ...
- Linux下那些奇葩的命令
相信喜爱编程,痴迷技术的你,肯定接触过甚至深爱着linux,甚至可能已经很熟悉linux了,可是linux那逗比的一面,你又知道多少. 本文!纯粹娱乐!不喜勿喷! 1.程序猿的愤慨! yes 当我们再 ...
- ExtJS4.2学习(11)——高级组件之Grid
大纲: 1.首先,搭建起来一个最基础的Grid组件: 2.其次,利用前边MVC架构将代码重构: 3.再者,介绍下Grid的一些特性. 一.搭建基础的Grid组件 在文章的开始,我们首先简单的搭建一个G ...
- springmvc入门详解
首先,我们先写一个入门小案例,先熟悉一下springmvc是什么,了解一下springmvc的运行流程,对加强springmvc的深层理解有很大帮助 .第一步,创建一个maven项目: <?xm ...
- Linux学习一些在Terminal可以用到的快捷键及Shell常用的通配符
Ctrl+c 终断程序 Ctrl+d 键盘输入结束或退出终端 Ctrl+s 暂定当前程序,暂停后按下任意键恢复运行 Ctrl+z 将当前程序放到后台运行,恢复到前台为命令fg Ctrl+a 将光标移至 ...
- 关于ajax网络请求的封装
// 封装的ajax网络请求函数// obj 是一个对象function AJAX(obj){ //跨域请求 if (obj.dataType == "jsonp") ...
- python 下的数据结构与算法---3:python内建数据结构的方法及其时间复杂度
目录 一:python内部数据类型分类 二:各数据结构 一:python内部数据类型分类 这里有个很重要的东西要先提醒注意一下:原子性数据类型和非原子性数据类型的区别 Python内部数据从某种形式上 ...
- 导出Exexcl类
前台: <%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation=" ...
- CGRectInset CGRectoffset UIEdgeInsetsInsetRect 这三个函数的使用情况
//CGRectInset 将原来的矩形放大或者缩小,正表示缩小,-表示放大. CGRect rect= CGRectMake(20, 50, 100, 80); CGRect rect1=CGRec ...
- effective条款15,在资源管理类中小心copying行为
class A { private: int *p; void lock(){ cout << p << "is lock" << endl; ...