Solved

Magic Number

Posted on 2009-04-10
4
3,032 Views
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
49999999999999999999
1787109375
12890625
4218751
2890624
3751

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

0
Comment
Question by:palhade
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
johnnash1180 earned 250 total points
ID: 24121276
Try out using the C++ big integer library available at http://mattmccutchen.net/bigint/

Hope it fulfills your requirement.

John Nash
0
 
LVL 7

Expert Comment

by:johnnash1180
ID: 24121282
You can get more details on large number arithmetic from the http://en.wikipedia.org/wiki/Arbitrary_precision_arithmetic URL.
0
 
LVL 25

Assisted Solution

by:InteractiveMind
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
0
 
LVL 25

Expert Comment

by:InteractiveMind
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[])
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
computer science syllabus 3 81
Create a path if not exists 7 77
passing data from one form to another form in c++ 27 79
A  &&  B  || (C||D) how it works in c 7 53
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: Nadia
Linear search (searching each index in an array one by one) works almost everywhere but it is not optimal in many cases. Let's assume, we have a book which has 42949672960 pages. We also have a table of contents. Now we want to read the content on p…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

776 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