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个三个以上不同的素数相乘的值(从小到大排),但是只要求三个不同的,也就意味着第五个第六个可以是相同的,如果只是暴力打表求三个不同素数的值,那会漏了很多情况,比如第三个应该是2*3*5*2=60. 思路:枚举从30-10000个数,进行分解质因数,如果能分解出三个以上,则将该数字存到另一个数组,一开始想破脑袋都没想出来,后来看了一下数据范围和通过人数,就知道应该是暴力求解,果然没超时! 代码:
 #include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[];
int ss(int n)//分解质因数
{
int q,w,e,c=;
int t=n;
for(int i=;i<=n;i++)
{
if(n%i==)//如果i为因数就+1
c++;
while(n%i==)//去掉重复的因数
{
n/=i;
}
if(n==)
break;
}
if(c>=)//如果质因数大于等于3则说明该数字符合条件
return ;
else
return ;
}
int main()
{
int m=,c=;
long long ans[];
for(int i=;i<=;i++)//应该第一个样例告诉了你开头是30,所以直接从30枚举。
{
if(ss(i))
a[c++]=i;//保存在数组里,方便直接输出。
}
int t,n;
cin>>t;
while(t--)
{
cin>>n;
cout<<a[n-]<<endl;//因为数从小到大枚举所以直接就可以输出
}
return ;
}
 

SPOJ - AMR11E的更多相关文章

  1. SPOJ AMR11E Distinct Primes 基础数论

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

  2. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  3. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  4. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  5. 【填坑向】spoj COT/bzoj2588 Count on a tree

    这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...

  6. SPOJ bsubstr

    题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...

  7. 【SPOJ 7258】Lexicographical Substring Search

    http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...

  8. 【SPOJ 1812】Longest Common Substring II

    http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个 ...

  9. 【SPOJ 8222】Substrings

    http://www.spoj.com/problems/NSUBSTR/ clj课件里的例题 用结构体+指针写完模板后发现要访问所有的节点,改成数组会更方便些..于是改成了数组... 这道题重点是求 ...

随机推荐

  1. 利用PowerShell监控Win-Server性能

    Q:如何系统层面的去监控一下Windows Server? A:额……一时间的话……能想到的可能也就是PowerShell+SQL Server+job,试试. 1.关于PowerShell 2.Po ...

  2. Let's Encrypt泛域名SSL证书申请

    操作系统:CentOS 7 github:https://github.com/Neilpang/acme.sh 有中文说明: https://github.com/Neilpang/acme.sh ...

  3. SpringBoot入坑-请求参数传递

    前一篇我们探讨了关于springboot的配置文件和Controller的使用,本篇我们来一起探讨一下关于springboot如何传递参数的知识. 参数传递我们最常见的就是在url后通过?/& ...

  4. IntelliJ IDEA 2018.3.2无法正常输入字符问题解决方案

    昨天升级IDEA的版本到2018.3.2,今天打开项目发现只要在代码编辑器输入字符(英文.符号或中文等)都会立刻被强制删除,造成一个无法正常输入的现象(回车换行可以).仔细观察这种想象后发有可能是代码 ...

  5. 【CF961G】Partitions 第二类斯特林数

    [CF961G]Partitions 题意:给出n个物品,每个物品有一个权值$w_i$,定义一个集合$S$的权值为$W(S)=|S|\sum\limits_{x\in S} w_x$,定义一个划分的权 ...

  6. [WCF] Restful 自定义宿主

    IPersonRetriever: /* * 由SharpDevelop创建. * 用户: Administrator * 日期: 2017/6/2 * 时间: 22:13 * * 要改变这种模板请点 ...

  7. 11.17 luffycity(7)完结

    2018-11-17 15:59:01 路飞项目已经完结!后面已是flask的学习!然后还有十几天的课程等回学校再看 明天归校!!  开始全面整理自己学习的知识,整理博客!还有好多面试题!233333 ...

  8. eclipse主题之-------DevStyle

    最佳因为经常熬夜  eclipse自带的背景 白色 太伤眼了 换了其他颜色但是 总感觉 差点什么    所以就去eclipse自带的插件下载中心 下载了  DevStyle 其实 有很多的 主题插件的 ...

  9. ora-01017 和oracle database link

    DB link ,创建完了后总是报密码错误.我感到奇怪.明明密码是对的.怎么可能错误呢. SQL> create public database link kk40 connect to khf ...

  10. hive reduce 阶段GC Exception

    某个reduce中的value堆积的对象过多,导致jvm频繁GC. 解决办法: 1. 增加reduce个数,set mapred.reduce.tasks=300,. 2. 在hive-site.xm ...