码迷,mamicode.com
首页 > 其他好文 > 详细

2018HDU多校训练-3-Problem D. Euler Function

时间:2018-07-31 23:26:39      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:targe   span   个数   hat   技术   ref   composite   put   mes   

链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322

Problem Description
In number theory, Euler‘s totient function φ(n)技术分享图片 counts the positive integers up to a given integer n技术分享图片 that are relatively prime to n技术分享图片 . It can be defined more formally as the number of integers k技术分享图片 in the range 1kn技术分享图片 for which the greatest common divisor gcd(n,k)技术分享图片 is equal to 1技术分享图片 .
For example, φ(9)=6技术分享图片 because 1,2,4,5,7技术分享图片 and 8技术分享图片 are coprime with 9技术分享图片 . As another example, φ(1)=1技术分享图片 since for n=1技术分享图片 the only integer in the range from 1技术分享图片 to n技术分享图片 is 1技术分享图片 itself, and gcd(1,1)=1技术分享图片 .
A composite number is a positive integer that can be formed by multiplying together two smaller positive integers. Equivalently, it is a positive integer that has at least one divisor other than 1技术分享图片 and itself. So obviously 1技术分享图片 and all prime numbers are not composite number.
In this problem, given integer k技术分享图片 , your task is to find the k技术分享图片 -th smallest positive integer n技术分享图片 , that φ(n)技术分享图片 is a composite number.
 
Input
The first line of the input contains an integer T(1T100000)技术分享图片 , denoting the number of test cases.
In each test case, there is only one integer k(1k10技术分享图片9技术分享图片)技术分享图片 .
 
Output
For each test case, print a single line containing an integer, denoting the answer.
 
Sample Input
2 1 2
 

 

Sample Output
5 7
 

 

Source
 

 

Recommend
chendu   |   We have carefully selected several similar problems for you:  6331 6330 6329 6328 6327 
题解:给你一个数k,让你求让你求第k 个gcd(num,x)的个数为合数(除了1)的num,x为从1 ~ num-1,这题题名写着欧拉函数,很明显让你求第k个欧拉函数值为合数的数;
显然,由于大于3的质数都满足题意(根据欧拉函数知道,质数的欧拉函数值为x-1,必为大于2的偶数)
对于奇数: 有当m,n互质时,有f(mn)=f(m)f(n),根据任何数都可以由多个质数的多少次幂相乘得到,故,对于质数num,其可以由一个质数乘另一个数得到,质数和任意数都是互质的,故f(num)=f(x)f(y){假设x为质数},则,f(num)=(x-1)*f(y),由(x-1)为偶数,且f(y)>1,则对于任意奇数都是满足题意的;
对于偶数:由上同理可以推出只有6不满足题意:故只要排除6即可;从4开始遍历:
参考代码为:
#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	long long k;
	cin>>t;
	while(t--)
	{
		cin>>k;
		if(k==1) cout<<5<<endl;
		else cout<<k+5<<endl;
	}
	return 0;
}

  

2018HDU多校训练-3-Problem D. Euler Function

标签:targe   span   个数   hat   技术   ref   composite   put   mes   

原文地址:https://www.cnblogs.com/songorz/p/9398398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!