Big numbers

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 6
Reputation: nameless987 is an unknown quantity at this point 
Solved Threads: 0
nameless987 nameless987 is offline Offline
Newbie Poster

Big numbers

 
0
  #1
Sep 11th, 2008
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!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,468
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1477
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Big numbers

 
0
  #2
Sep 11th, 2008
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 6
Reputation: nameless987 is an unknown quantity at this point 
Solved Threads: 0
nameless987 nameless987 is offline Offline
Newbie Poster

Re: Big numbers

 
0
  #3
Sep 12th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 236
Reputation: TheBeast32 is on a distinguished road 
Solved Threads: 6
TheBeast32's Avatar
TheBeast32 TheBeast32 is offline Offline
Posting Whiz in Training

Re: Big numbers

 
0
  #4
Sep 12th, 2008
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/
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live."
--Martin Golding
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 6
Reputation: nameless987 is an unknown quantity at this point 
Solved Threads: 0
nameless987 nameless987 is offline Offline
Newbie Poster

Re: Big numbers

 
0
  #5
Sep 12th, 2008
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/
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 206
Reputation: grumpier has a spectacular aura about grumpier has a spectacular aura about 
Solved Threads: 31
grumpier grumpier is offline Offline
Posting Whiz in Training

Re: Big numbers

 
0
  #6
Sep 12th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 236
Reputation: TheBeast32 is on a distinguished road 
Solved Threads: 6
TheBeast32's Avatar
TheBeast32 TheBeast32 is offline Offline
Posting Whiz in Training

Re: Big numbers

 
0
  #7
Sep 12th, 2008
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.
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live."
--Martin Golding
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 6
Reputation: nameless987 is an unknown quantity at this point 
Solved Threads: 0
nameless987 nameless987 is offline Offline
Newbie Poster

Re: Big numbers

 
0
  #8
Sep 12th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 236
Reputation: TheBeast32 is on a distinguished road 
Solved Threads: 6
TheBeast32's Avatar
TheBeast32 TheBeast32 is offline Offline
Posting Whiz in Training

Re: Big numbers

 
1
  #9
Sep 12th, 2008
i'll attack the devpak! =)
Attached Files
File Type: zip GMP.zip (816.9 KB, 12 views)
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live."
--Martin Golding
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 206
Reputation: grumpier has a spectacular aura about grumpier has a spectacular aura about 
Solved Threads: 31
grumpier grumpier is offline Offline
Posting Whiz in Training

Re: Big numbers

 
0
  #10
Sep 13th, 2008
Originally Posted by nameless987 View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC