Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-22-2006, 05:46 AM
tim1234 tim1234 is offline
Newbie
 
Join Date: Dec 2006
Posts: 4
Rep Power: 0
tim1234 is on a distinguished road
Default Large powers

How would you write an algorithm in C to calculate large numbers raised to large numbers modulo n. (numbers in the 10,000s) so obviously can't just do it straight off.

I tried working out x, x^2, x^4 and somehow using the binary representation of the power to work it out but I have no idea how to program this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 12-22-2006, 12:51 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,418
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

Code:
int power(int base, int exponent, int modulo)
{
  if exponent=1 return base % modulo;
  if not (exponent % 2)
     return power(base*base%modulo,exponent/2,modulo)
  else
     return power(base*base%modulo,exponent/2,modulo)*base%modulo;
}
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-22-2006, 05:18 PM
DevilsCharm's Avatar   
DevilsCharm DevilsCharm is offline
Programming God
 
Join Date: Jul 2006
Posts: 887
Rep Power: 14
DevilsCharm is on a distinguished road
Default

A power to the 10,000? That's really large, although I've always thought if supercomputers can process really, really, really big numbers.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-22-2006, 05:18 PM
xXHalfSliceXx's Avatar   
xXHalfSliceXx xXHalfSliceXx is offline
Co-Administrator
 
Join Date: Oct 2006
Location: Hendersonville, NC
Age: 24
Posts: 1,238
Rep Power: 20
xXHalfSliceXx is on a distinguished road
Send a message via AIM to xXHalfSliceXx Send a message via MSN to xXHalfSliceXx Send a message via Yahoo to xXHalfSliceXx
Default

Sounds like we are doing your HW for you? 0_o

Good Luck
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Company
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-23-2006, 04:19 AM
TcM's Avatar   
TcM TcM is offline
Code Warrior
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,332
Rep Power: 68
TcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of lightTcM is a glorious beacon of light
Default

Quote:
Originally Posted by WingedPanther View Post
Code:
int power(int base, int exponent, int modulo)
{
  if exponent=1 return base % modulo;
  if not (exponent % 2)
     return power(base*base%modulo,exponent/2,modulo)
  else
     return power(base*base%modulo,exponent/2,modulo)*base%modulo;
}
When theres Math.. WingedPanther is the one
Good Job
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 12-29-2006, 12:29 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,418
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

Maybe I should write some tutorials about math in programming.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with large numbers saurav C and C++ 4 10-11-2007 05:52 PM
large floating point calculations zeos386sx General Programming 5 04-02-2007 03:31 AM
Large list of PAD enabled shareware web sites UtilityW Shareware Sites 2 08-24-2006 09:56 PM
Large list of PAD enabled shareware web sites UtilityW Marketing 5 07-21-2006 11:45 AM


All times are GMT -5. The time now is 02:04 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads