Magic Number

Posted on 2009-04-10
Last Modified: 2012-05-06
I have to write progarm for following problem -
File contain numbers. Numbers can be of 20 digits. I want to write program so that it can print number - with following property

75 * 75 * 75 = 421875 (last two digits are 75)
501 * 501 * 501 = 125751501 (again last 3 difits are same as 501)

Following numbers are also have same property

Please help me to solve this problem. I am sure strig need to use for it as there is no datatype that store number for 20 digits and its cube.

Open in new window

Question by:palhade
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Accepted Solution

johnnash1180 earned 250 total points
ID: 24121276
Try out using the C++ big integer library available at

Hope it fulfills your requirement.

John Nash

Expert Comment

ID: 24121282
You can get more details on large number arithmetic from the URL.
LVL 25

Assisted Solution

InteractiveMind earned 250 total points
ID: 24122079
The last three digits of n^3 only depend on the last three digits of n.

If n consists of a units, b tens, and c hundreds, then the last three digits of n^3 will be:

  (a^3 + 3a^2*b*10 + 3a^2*c*100 + 2a*b^2*100) % 1000
LVL 25

Expert Comment

ID: 24122124
(So, for example, read the number into a char[], cast the last three digits to integers, perform the above check. If it equals the last three digits then it's a 'magic number', so put the char[])

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Okay. So what exactly is the problem here? How often have we come across situations where we need to know if two strings are 'similar' but not necessarily the same? I have, plenty of times. Until recently, I thought any functionality like that wo…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question