Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3044
  • Last Modified:

Magic Number

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
palhade
Asked:
palhade
  • 2
  • 2
2 Solutions
 
johnnash1180Commented:
Try out using the C++ big integer library available at http://mattmccutchen.net/bigint/

Hope it fulfills your requirement.

John Nash
0
 
johnnash1180Commented:
You can get more details on large number arithmetic from the http://en.wikipedia.org/wiki/Arbitrary_precision_arithmetic URL.
0
 
InteractiveMindCommented:
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
 
InteractiveMindCommented:
(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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now