Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9251325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:40:13+00:00 2026-06-18T10:40:13+00:00

Description: A positive integer m is said to a pure number if and only

  • 0

Description:

A positive integer m is said to a pure number if and only if m can be
expressed as q-th power of a prime p (q >= 1). Here your job is easy,
for a given positive integer k, find the k-th pure number.

Input:

The input consists of multiple test cases. For each test case, it
contains a positive integer k (k<5,000,000). Process to end of file.

Output:

For each test case, output the k-th pure number in a single line. If
the answer is larger than 5,000,000, just output -1.

Sample input:

1

100

400000

Sample output:

2

419

-1

Original page: http://acm.whu.edu.cn/learn/problem/detail?problem_id=1092

Can anyone give me some suggestion on the solution to this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:40:14+00:00Added an answer on June 18, 2026 at 10:40 am

    You’ve already figured out all the pure numbers, which is the tricky part. Sort the ones less than 5 million and then look up each input in turn in the resulting array.

    To optimize you need to efficiently find all primes up to 5 million (note q >= 1 in the problem description: every prime is a pure number), for which you will want to use some kind of sieve (sieve of Erathosthenes will do, look it up).

    You could probably adapt the sieve to leave in powers of primes, but I expect that it would not take long to sieve normally and then put the powers back in. You only have to compute powers of primes p where p <= the square root of 5 million, which is 2236, so this shouldn’t take long compared with finding the primes.

    Having found the numbers with a sieve, you no longer need to sort them, just copy the marked values from the sieve to a new array.

    Having now looked at your actual code: your QuickSort routine is suspect. It performs badly for already-sorted data and your array will have runs of sorted numbers in it. Try qsort instead, or if you’re supposed to do everything yourself then you need to read up on pivot choice for quicksort.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple enum: public enum MyEnum { [Description(Zero)] Zero, [Description(A positive number)]
the description of them in http://www.khronos.org/opengles/sdk/docs/man/ are almost same. The only difference is the
Description: the query actually run have 4 results returned,as can be see from below,
So there is a website named interviewstreet.com. Here we can find challenging programming problems.
Description: Given an array consists of n positive integers, find the largest C which
description_id description -------------- ------------- 1 Ampicillin Oral 1 Ofloxacin Oral 1 Sulfamoxole+Trimethoprim Oral 2
Description: If we use java objects jruby get permgen too: System.out.println(Initialazing..); //Spring applicaton context
Description : I am creating customized title bar. The codes for customization is as
Description: An unhandled exception occurred during the execution of the current web request. Please
Description: I have a problem regarding DataGridView . I need to show a Client_Name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.