csu 1282 Sphenic Number 暴力 解题报告

Description

We call a number is a sphenic number if it is a product of 3 distinct primes. The smallest 10 sphenic numbers are 30, 42, 66, 70, 78, 102, 105, 110, 114, 130. Now you need to find the Kth smallest sphenic number.

Input

There is an integer T (1 <= T <= 10^5) in the first line, indicates there are T test cases in total.

Each test case contains one line with an integer K (1 <= K <= 10^5), indicates you need to find the Kth smallest sphenic number.

Output

For each test case, you should print the Kth smallest sphenic number in one line.

Sample Input

2110

Sample Output

30130

思路:暴力,先用素数筛选法,然后暴力组合,然后排序。注意范围, 不断缩小范围。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

long long ans[1500005];

long long p[200005], a[200005], tt = 0;
void prime()
{
    int i, n=130000, j;
    a[1] = 0;
    for(i = 2; i <= n; i++)
        a[i] = 1;
    for(i = 2; i <= n; i++)
        if(a[i])
        {
            p[tt++] = i;
            for(j = i; j <= n;j += i)
                a[j] = 0;
        }
}
int main()
{
    prime();
    int T, n, t = 0;
    for(int i = 0; i < tt; i++)
    {
        for(int j = i + 1; j < tt; j++)
        {
            for(int k = j + 1; k < tt; k++)
            {
                if(p[i] * p[j] * p[k]>539251)
                    break;
                ans[t++] = p[i] * p[j] * p[k];
            }
        }
    }
    sort(ans, ans + t);
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d", &n);
        printf("%lld\n", ans[n - 1]);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值