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

链接: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 1≤k≤n 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(1≤T≤100000)

, denoting the number of test cases.
In each test case, there is only one integer k(1≤k≤109)

.

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

2018 Multi-University Training Contest 3

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;
}

  

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

时间: 2024-11-06 17:33:31

2018HDU多校训练-3-Problem D. Euler Function的相关文章

Problem D. Euler Function

Problem D. Euler Function 题目: Problem D. Euler Function http://acm.hdu.edu.cn/showproblem.php?pid=6324 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 66    Accepted Submission(s): 64 Problem

2018HDU多校训练-3-Problem M. Walking Plan

链接:http://acm.hdu.edu.cn/showproblem.php?pid=6331 Walking Plan Problem Description There are n intersections in Bytetown, connected with m one way streets. Little Q likes sport walking very much, he plans to walk for q days. On the i -th day, Little

多校训练hdu --Nice boat(线段树,都是泪)

Nice boat Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 47 Accepted Submission(s): 10 Problem Description There is an old country and the king fell in love with a devil. The devil always ask

hdu 4970 Killing Monsters(简单题) 2014多校训练第9场

Killing Monsters                                                                        Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description Kingdom Rush is a popular TD game, in which you should b

hdu 4923 Room and Moor(数学题)2014多校训练第6场

Room and Moor                                                                          Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem Description PM Room defines a sequence A = {A1, A2,..., AN}, each of

hdu 4902 Nice boat(2014多校训练第4场 1006)

Nice boat                                                                           Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description There is an old country and the king fell in love with a d

hdu 4960 Another OCD Patient(dp)2014多校训练第9场

Another OCD Patient                                                                         Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description Xiaoji is an OCD (obsessive-compulsive disorder) pat

hdu 4965 Fast Matrix Calculation(矩阵快速幂)2014多校训练第9场

Fast Matrix Calculation                                                                   Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description One day, Alice and Bob felt bored again, Bob knows Ali

hdu 4920 Matrix multiplication(矩阵相乘)多校训练第5场

Matrix multiplication                                                                           Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description Given two matrices A and B of size n×n, find the