Write a program to count how many integers from 1 to 1000 are not perfect squares, perfect cubes, or perfect fifth powers

how to get numbers that are not perfect squares or perfect cube or perfect fifth

Replies

  • Kaustubh Katdare
    Kaustubh Katdare

    I'll give you an algorithm and would like you to try writing the program on your own. If after trying you are unable to figure out the program, I'll show you how it's done. Okay? 

    Question: How do we find out whether a number is a perfect square? 

    Answer: Find out the square root of the number and check if it's an integer. 

    The same applies to any 'nth' root of a number. If it's an integer; you can say that it's a perfect nth power. 

    With that knowledge, the approach will be like this- 

    1. Run a loop 1000 times each time incrementing the number by 1. 

    2. In every loop, write multiple if conditions to check if it fits in the given criteria - that is, the nth root of the number (where n = 2, 3 or 5) is an integer. If it is not, the number fits in our criteria. Increment our final counter by 1. 

    3. When you exit out of the loop, you will have the final counter set to the count of numbers that are not nth roots of any number 2,3 or 5. 

    Give it a try. You will have to find out which functions are available in the programming language that you are using. Hint: Look for 'pow' function, which lets you calculate nth power of any number. If you want to use it to calculate square root, you will set 'n' to 1/2. For cube root, set it to 1/3. 

    I hope this works. Give it a try and paste your attempt below. If you are unable to figure out the solution, I'll post the answer. 

You are reading an archived discussion.

Related Posts

The project enable users to enter personal details and login required passwords,able to solve community based problems
Google's got an awesome text adventure game hidden right inside the Chrome browser. Here's how to play it -Search "Text Adventure" in Google search.Now open the Developer Console. It's easy...
we are already manufacturing  horns for past 20 years but now we need a new assembly line for a new  factory set up
My Seagate hard disk is not detecting. I am not able to find any authorized service centre in Andhra Pradesh. I am afraid giving to third parties. 
For what it is worth."Instructables" says this:Why would you want to do this? Well computers really have not gotten that much better(at least CPU wise) in the last decade so...