hdu1286找新朋友 欧拉函数模板题

#include<cstdio>

#include<cstring>

#include<iostream>

using namespace std ;

int Euler(int n)

{

int rea = n ;

for(int i = 2;i*i <= n;i++)

{

if(n%i == 0)

rea -= rea/i ;

while(n%i == 0)

n/=i ;

}

if(n>1)

rea-=rea/n ;

return rea ;

}

int main()

{

int T ;

int n ;

scanf("%d" ,&T) ;

while(T--)

{

scanf("%d" , &n) ;

printf("%d\n" ,Euler(n)) ;

}

return  0 ;

}

时间: 2024-08-06 20:05:30

hdu1286找新朋友 欧拉函数模板题的相关文章

hdu-1286 找新朋友(欧拉函数,水题)

题目链接: 找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10120    Accepted Submission(s): 5344 Problem Description 新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有

(hdu step 2.1.6)找新朋友(欧拉函数的简单使用:求与n互质的元素的个数)

题目: 找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2788 Accepted Submission(s): 1307   Problem Description 新年快到了,"猪头帮协会"准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大

hdu 1286 找新朋友 (欧拉函数)

Description 新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来. Input 第一行是测试数据的组数CN(Case number,1<CN<10000),接着有CN行正整数N(1<n<32768),表示会员人数. Output 对于每一个N,输出一行新朋友的人数,这样共有CN行输出

杭电ACM1286——找新朋友~欧拉函数的应用

欧拉函数 欧拉函数,对于正整数n,欧拉函数就是小于或者等于n的数中与n互质的数的数目. 通式为: F(x) = x * (1 - 1 / p1) * (1 - 1 / p2) * ....... * (1 - 1 / pn):p1,p2,p3.....pn为x的质因子.每一质因子只出现一次.即p1 ≠ p2 ≠ ....pn: 例如12 = 2 * 2 * 3:2只能算一次. 有了这个欧拉通式,便可以快速的求解这一题,该开始我是用普通的方法做的,很明显,超时了,一次输入的数很多个的时候,便容易超

hdu2824 The Euler function 筛选法求欧拉函数模板题

//求a , b范围内的所有的欧拉函数 //筛选法求欧拉函数模板题 #include<cstdio> #include<cstring> #include<iostream> using namespace std ; const int maxn = 3000010 ; typedef __int64 ll ; int e[maxn] ; int a ,  b ; void Euler() { int i,j; for (i=1;i<maxn;i++) e[i]

(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/Others) Total Submission(s): 166 Accepted Submission(s): 96   Problem Description The Euler function phi is an important kind of function in number theory

poj2407(欧拉函数模板题)

题目链接:https://vjudge.net/problem/POJ-2407 题意:给出n,求0..n-1中与n互质的数的个数. 思路:欧拉函数板子题,先根据唯一分解定理求出n的所有质因数p1,p2,...,pn,然后根据Φ(m)=m*∏(1-1/pi)计算即可. AC代码: #include<cstdio> using namespace std; int n,ans; int main(){ while(scanf("%d",&n),n){ ans=n; f

HDU1286新朋友欧拉函数版

找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10401    Accepted Submission(s): 5493 Problem Description 新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约

数论 - 欧拉函数模板题 --- poj 2407 : Relatives

Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11372   Accepted: 5544 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 ther