943,866 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3075
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 11th, 2008
0

Big numbers

Expand Post »
Hey... do anyone knows c++ function for implementation of big numbers...i tried googl it...but, i can't find nothing that solve my problem

i need to calculate a^e(mod n)

example:

125^107 (mod 187)=5

result of 125^107 is too big for standard notation in c++...

can someone please help me!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nameless987 is offline Offline
6 posts
since Sep 2008
Sep 11th, 2008
0

Re: Big numbers

Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,951 posts
since Aug 2005
Sep 12th, 2008
0

Re: Big numbers

Now I have problem with fmod...

i calculated with y=pow(a,e)

then fmod(y,n)... but now i seems that that fmod has to small range of results (same thing is with %)
is there some other function for mod?
Last edited by nameless987; Sep 12th, 2008 at 8:25 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nameless987 is offline Offline
6 posts
since Sep 2008
Sep 12th, 2008
0

Re: Big numbers

Use the GMP library. It works for me. If you're using Dev-C++, you can just search for packages online with the built in "Check for updates/packages" thing, and find it in the list. If not go here: http://gmplib.org/
Reputation Points: 79
Solved Threads: 6
Posting Whiz in Training
TheBeast32 is offline Offline
236 posts
since Dec 2007
Sep 12th, 2008
0

Re: Big numbers

How to instal GMP library....dev c++ won'r downlod it, and i don't knoe how to install one i have downloaded from http://gmplib.org/
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nameless987 is offline Offline
6 posts
since Sep 2008
Sep 12th, 2008
0

Re: Big numbers

Talking about using a sledgehammer to crack a nut. No need to use high precision integers at all.

(a^b) mod c can be evaluated using a loop, using modulo arithmetic.

The basic property you need to know is that (x*y) mod z is equal to ((x mod z)*(y mod z)) mod z). From that it is possible to compute (a^b) mod c. I'll leave the precise code as an exercise.
Reputation Points: 193
Solved Threads: 32
Posting Whiz in Training
grumpier is offline Offline
206 posts
since Aug 2008
Sep 12th, 2008
0

Re: Big numbers

Dev-C++ WILL download it. You have to pick the option in the package downloader that says community devpaks, scroll down and find it. Download it, and it should automatically bring you to an installer.
Last edited by TheBeast32; Sep 12th, 2008 at 2:52 pm.
Reputation Points: 79
Solved Threads: 6
Posting Whiz in Training
TheBeast32 is offline Offline
236 posts
since Dec 2007
Sep 12th, 2008
0

Re: Big numbers

I tried to download it in that way...but i get some error that this file doesn't exist..

i figured out that i must use this kind calculations if i want to work with big nombers:
P = Cd % n
= 62^65 % 133
= 62 * 62^64 % 133
= 62 * (62^2)32 % 133
= 62 * 3844^32 % 133
= 62 * (3844 % 133)^32 % 133
= 62 * 120^32 % 133
.
.
.
= 62 * 36^16 % 133
= 62 * 99^8 % 133
= 62 * 92^4 % 133
= 62 * 85^2 % 133
= 62 * 43 % 133
= 2666 % 133
= 6


How can i write this in c++?
please help
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nameless987 is offline Offline
6 posts
since Sep 2008
Sep 12th, 2008
1

Re: Big numbers

i'll attack the devpak! =)
Attached Files
File Type: zip GMP.zip (816.9 KB, 71 views)
Reputation Points: 79
Solved Threads: 6
Posting Whiz in Training
TheBeast32 is offline Offline
236 posts
since Dec 2007
Sep 13th, 2008
0

Re: Big numbers

i figured out that i must use this kind calculations if i want to work with big nombers:
P = Cd % n
= 62^65 % 133
= 62 * 62^64 % 133
= 62 * (62^2)32 % 133
= 62 * 3844^32 % 133
= 62 * (3844 % 133)^32 % 133
= 62 * 120^32 % 133
.
.
.
= 62 * 36^16 % 133
= 62 * 99^8 % 133
= 62 * 92^4 % 133
= 62 * 85^2 % 133
= 62 * 43 % 133
= 2666 % 133
= 6


How can i write this in c++?
please help
Try to express it as a loop construct. Your logic here is, mathematically, equivalent to what I said in my previous post.
Last edited by grumpier; Sep 13th, 2008 at 1:13 am.
Reputation Points: 193
Solved Threads: 32
Posting Whiz in Training
grumpier is offline Offline
206 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: stuck with abstract class, function overriding
Next Thread in C++ Forum Timeline: Need help displaying my array





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC