UESTC Summer Training #2 Div.2 E decomposition factor (except for the remainder may be a prime number)

Source: Internet
Author: User

E-ETime limit:MS Memory Limit:1572864KB 64bit IO Format:%lld &%llu SubmitStatusPracticeSpoj amr11e

Description

Arithmancy is Draco Malfoy's favorite subject, what if spoils it for him was that Hermione Granger was in his class, and SH  E is better than him at it. Prime numbers is of mystical importance in arithmancy, and Lucky numbers even. Lucky Numbers is those positive integers that has at least three distinct prime factors; and is the first. Malfoy ' s teacher has given them a positive an integer n, and has asked them to find the nth lucky number.  Malfoy would like to beat Hermione on this exercise, so although he's an evil git, please help him, just this once. After all, the know-it-all Hermione does need a lesson. Input (STDIN): The first line contains the number of test cases T. Each of the next T lines contains one integer n.output (STDOUT): Output T lines, containing the corresponding lucky number For the test case. Constraints:1 <= T <= 201 <= n <= 1000Time limit:2 smemory limit:32 mbsample input:212sample Output:3042

Arithmancy is Draco Malfoy's favorite subject, what if spoils it for him was that Hermione Granger was in his class, and SH E is better

than him at it. Prime numbers is of mystical importance in arithmancy, and Lucky numbers even. Lucky Numbers is

Those positive integers that has at least three distinct prime factors; and is the first. Malfoy ' s teacher has given them a positive an integer n, and has asked them to find the nth lucky number. Malfoy would like to beat Hermione @ this exercise, so although

He is a evil git, please help him, just this once. After all, the know-it-all Hermione does need a lesson.

Input (STDIN):

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

Output (STDOUT):

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

Constraints:

1 <= T <= 20

1 <= N <= 1000

Sample Input:

2

1

2

Sample Output:

30

42

Hint

Added by: Varun Jalan
Date: 2011-12-15
Time limit: 3s
Source limit: 50000B
Memory limit: 1536MB
Cluster: Cube (Intel G860)
Languages: All
Resource: Varun JALAN-ICPC Asia Regionals, Amritapuri 2011

Source

Http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121703#problem/E


My Solution

Decomposition factorization, at least three different qualitative factors are lucky number, with the modified decomposition factorization template, is only a record of the quality because of the number of good, no tube is what and different quality because a number of more than equals 3 return 3

The decomposition of the quality factor template do not know why WA, changed to 2~n, violent try to decompose factorization can @@facesymbol@@‖∣

Reason, for 2~SQRT (n) +1, there may be more than sqrt (n) +1 of the prime number, which is also greater than sqrt (n) +1 of the qualitative factor, so try to remove all the 2~n is better

When we first started, I thought that there were only three numbers of different prime numbers, and then we made a list of primes, then we constructed them and then saved them with small Gan, and then took the smallest of more than 10 million according to the required number to thisans[].

(┬_┬) wasted a lot of time

#include <iostream> #include <cstdio> #include <cstring> #include <cmath>using namespace std;    typedef long LONG Ll;const int maxn = 20000 + 9;int ans[maxn];int factor (int n) {int tot = 0;    int temp, I, now;    temp = (int) ((double) sqrt (n) + 1);    now = n; for (int i = 2; I <= n; i++) {//!!!!!!            Why not use temp if (now%i = = 0) {tot++;        if (Tot >= 3) return tot;        } while (now%i = = 0) {now/=i; }} return tot;}    int main () {int t = 1, num = 2;        while (T < 1009) {if (factor (num) >= 3) {ans[t] = num; t++;}    num++;    }//cout<<factor (4588) <<endl;    #ifdef LOCAL freopen ("A.txt", "R", stdin);    Freopen ("B.txt", "w", stdout);    #endif//LOCAL LL T, N;    cin>>t;        while (t--) {cin>>n;    cout<<ans[n]<<endl; } return 0;}



Thank you!

------ fromProlights
------ fromProlights

UESTC Summer Training #2 Div.2 E decomposition factor (except for the remainder may be a prime number)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.