mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Math

Reply
 
Thread Tools
Old 2010-10-11, 13:47   #1
kurtulmehtap
 
Sep 2009

22×32 Posts
Default mod p calculation help

Dear All,
I need to calculate X = (p-1/ 2q ) mod p
where p and q are primes.
Is there a better way than doing modular division?
kurtulmehtap is offline   Reply With Quote
Old 2010-10-11, 14:15   #2
Ken_g6
 
Ken_g6's Avatar
 
Jan 2005
Caught in a sieve

5×79 Posts
Default

Edit: No, I don't think I know of a better way, except that you can simplify (P-1) mod P.

Is this homework?

Last fiddled with by Ken_g6 on 2010-10-11 at 14:18
Ken_g6 is offline   Reply With Quote
Old 2010-10-11, 14:24   #3
kurtulmehtap
 
Sep 2009

22·32 Posts
Default

It's not homework,
I need to write a program that repeatedly calculates
X = (p-1/ 2q ) mod p

where p and q are primes and list the results starting from p=3 to q.

Instead of calling the Modular division subroutine every time I have a new prime p,
I would prefer to have a faster way.
In this case better means faster and simpler.
Thanks


Quote:
Originally Posted by Ken_g6 View Post
Define "better". Simpler? Probably not. Faster? Maybe.

Is this homework?
kurtulmehtap is offline   Reply With Quote
Old 2010-10-11, 15:02   #4
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

22×5×373 Posts
Default

Quote:
Originally Posted by kurtulmehtap View Post
It's not homework,
I need to write a program that repeatedly calculates
X = (p-1/ 2q ) mod p

where p and q are primes and list the results starting from p=3 to q.
If q is fixed and p varies, then I know no faster way.

There is a faster way if p is fixed and q varies.

Quote:
Instead of calling the Modular division subroutine every time I have a new prime p,
I would prefer to have a faster way.
In this case better means faster and simpler.
What could be simpler than the Euclidean algorithm?

If p is LARGE, I would recommend using a binary Extended Euclidean
Algorithm, rather than a classical one. If p is VERY LARGE, I would use
an FFT approach.

How big are p and q?

Last fiddled with by R.D. Silverman on 2010-10-11 at 15:02
R.D. Silverman is offline   Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Primorial calculation FreakyPotato Programming 7 2015-02-06 10:33
GHZ-days calculation Q tcharron PrimeNet 4 2014-06-27 23:27
P-1 probability calculation James Heinrich PrimeNet 33 2011-01-23 16:40
CPU Credit Calculation storm5510 Software 8 2009-09-25 21:06
MMO Property Calculation Bundu Puzzles 22 2009-09-22 01:30

All times are UTC. The time now is 17:06.


Mon Aug 2 17:06:36 UTC 2021 up 10 days, 11:35, 0 users, load averages: 2.41, 2.29, 2.23

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.