Arithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger is in his class, and she is better than him at it. Prime numbers are of mystical importance in Arithmancy, and Lucky Numbers even more so. Lucky Numbers are those positive integers that have at least three distinct prime factors; 30 and 42 are the first two. Malfoy's teacher has given them a positive integer n, and has asked them to find the n-th lucky number. Malfoy would like to beat Hermione at this exercise, so although he is an evil git, please help him, just this once. After all, the know-it-all Hermione does need a lesson.

Input

The first line contains the number of test cases T. Each of the next T lines contains one integer n.

Output

Output T lines, containing the corresponding lucky number for that test case.

Constraints

1 <= T <= 20
1 <= n <= 1000

Example

Sample Input:
2
1
2 Sample Output:
30
42

题意:找第n个由至少三个不同素因子组成的数。

思路:n<=1000直接暴力打表预处理

/** @Date    : 2016-12-11-19.01
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version :
*/
#include<bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; int pri[N];
int ans[10010];
int c = 0;
bool vis[N];
int prime()
{
MMF(vis);
for(int i = 2; i < N; i++)
{
if(!vis[i])
pri[c++] = i; for(int j = 0; j < c && pri[j]*i < N; j++)
{
vis[i * pri[j]] = 1;
if(i % pri[j] == 0)
break;
}
}
} int main()
{
prime();
int tot = 0;
for(int i = 0; i <= 10000; i++)
{
int t = i;
int cnt = 0;
for(int j = 0; j < c && pri[j]*pri[j] <= t; j++)
{
if(t % pri[j] == 0)
{
cnt++;
while(t % pri[j] == 0)
t /= pri[j];
}
}
if(t > 1)
cnt++;
if(cnt >= 3)
ans[tot++] = i;
}
int T;
scanf("%d", &T);
while(T--)
{
int n;
scanf("%d", &n);
printf("%d\n", ans[n - 1]);
}
return 0;
}

SPOJ AMR11E Distinct Primes 基础数论的更多相关文章

  1. SPOJ 10232. Distinct Primes

    Arithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger i ...

  2. (Problem 47)Distinct primes factors

    The first two consecutive numbers to have two distinct prime factors are: 14 = 2  7 15 = 3  5 The fi ...

  3. 【SPOJ】Distinct Substrings(后缀自动机)

    [SPOJ]Distinct Substrings(后缀自动机) 题面 Vjudge 题意:求一个串的不同子串的数量 题解 对于这个串构建后缀自动机之后 我们知道每个串出现的次数就是\(right/e ...

  4. 【SPOJ】Distinct Substrings/New Distinct Substrings(后缀数组)

    [SPOJ]Distinct Substrings/New Distinct Substrings(后缀数组) 题面 Vjudge1 Vjudge2 题解 要求的是串的不同的子串个数 两道一模一样的题 ...

  5. LightOJ1214 Large Division 基础数论+同余定理

    Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...

  6. HDU-1576 A/B 基础数论+解题报告

    HDU-1576 A/B 基础数论+解题报告 题意 求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973) (我们给定的A必能被B整除,且gcd(B,9973) = 1). 输入 数据 ...

  7. 【SPOJ】Distinct Substrings

    [SPOJ]Distinct Substrings 求不同子串数量 统计每个点有效的字符串数量(第一次出现的) \(\sum\limits_{now=1}^{nod}now.longest-paren ...

  8. RSA算法原理——(2)RSA简介及基础数论知识

    上期为大家介绍了目前常见加密算法,相信阅读过的同学们对目前的加密算法也算是有了一个大概的了解.如果你对这些解密算法概念及特点还不是很清晰的话,昌昌非常推荐大家可以看看HTTPS的加密通信原理,因为HT ...

  9. SPOJ 694. Distinct Substrings (后缀数组不相同的子串的个数)转

    694. Distinct Substrings Problem code: DISUBSTR   Given a string, we need to find the total number o ...

随机推荐

  1. php中array_map和array_walk的使用对比

    一.array_map() 1.array_map() 函数将用户自定义函数作用到数组中的每个值上,并返回用户自定义函数作用后的带有新值的数组,若函数作用后无返回值,则对应的新值数组中为空. 2.回调 ...

  2. 第一次课堂作业---circle

    链接:circle

  3. ARKit----学习一

    一.ARKit的简介 开始进入正题吧 ARKit在iOS 11上推出的一个AR移动平台,支持A9以上的处理器,不支持模拟器.ARKit使用相机捕捉现实世界,使用SceneKit,SpriteKit或者 ...

  4. TCP系列39—拥塞控制—2、拥塞相关算法及基础知识

    一.拥塞控制的相关算法 早期的TCP协议只有基于窗口的流控(flow control)机制而没有拥塞控制机制,因而易导致网络拥塞.1988年Jacobson针对TCP在网络拥塞控制方面的不足,提出了& ...

  5. noauth authentication required redis

    解决方案: 这是出现了认证的问题,是因为设置了认证密码. 127.0.0.1:6379> auth "yourpassword" 例如:

  6. flash builder 4.6在debug调试时需要系统安装flashplayer debug版本

    http://blog.csdn.net/cupid0051/article/details/46684295

  7. VS2013 “未找到与约束 ContractName Microsoft.Internal.VisualStudio.PlatformUI.ISolutionAttachedCollectionService RequiredTypeIdentity Microsoft.Internal.VisualStudio.PlatformUI.ISolutionAttachedCollectionService 匹配的导出”

    下面是我出错误的附加图片 这个错误导致无法打开项目. 解决方法: 解: C:\Users\Administrator\AppData\Local\Microsoft\VisualStudio\12.0 ...

  8. 修改IntelliJ IDEA代码头注释

  9. 【APS.NET Core】- Razor Page 使用jqgrid实现分页功能

    本文将使用jqgrid在Razor Page中实现分页功能. 前台 List.cshtml代码如下: @page @model ListModel @{ Layout = "~/Pages/ ...

  10. 【Docker 命令】- start/stop/restart命令

    docker start:启动一个或多少已经被停止的容器 docker stop:停止一个运行中的容器 docker restart :重启容器 语法: docker start [OPTIONS] ...