Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8807091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:17:21+00:00 2026-06-14T02:17:21+00:00

Edit – clarified I’m trying to implement modular exponentiation in Java using lagrange and

  • 0

Edit – clarified

I’m trying to implement modular exponentiation in Java using lagrange and the chinese remainder theorem.

For example, if N is 55, having been given the prime factors 5 and 11, phi is 40, so I know there are 40 numbers co-prime to N below 55. My instructor says the way to do it is “using Lagrange’s theorem, a few multiplications modulo 5 and 11 and CRT to combine both results”

My problem is how to I calculate these numbers? I need them to put them into a Chinese remainder theorem to finish the calculations, but I can’t think of a clever way to cycle through N using phi(n) as a result. N will be an extremely large number, at least 1024 bits. I could possibly be on the wrong track here, do I even need all of these primes?

I do suspect that the answer will be related to the extended euclid function, which I already have coded so if I need to use results from it that’s fine.

I don’t understand the code in How many numbers below N are coprimes to N? so it isn’t much help to me, and the math papers I look at I find very difficult to follow, the sum and product type notation baffles me a bit. Also, some answers use square roots and logs which aren’t really an option with a BigInteger (correct me if I’m wrong)

Can anyone give me an answer in plain English??

It’s ok to show me code, this is more of a learning exercise because the answer I’m going to submit uses Montgomery. (Yeah I know, bizarre that I could work out Montgomery from a math formula but this Lagrange plus CRT has me totally baffled)

I’ve gotten as far as this, working through an example I’ve found. The prime factors are seven and five, so phi of 35 is 24 (I have a working Euler totient function).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:17:21+00:00Added an answer on June 14, 2026 at 2:17 am

    See this answer for a worked-out example. It shows exactly how to perform modular exponentation modulo a composite by doing the operation modulo the prime factors, and combining the results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: iam using ajax to load text in my content that is why onload
EDIT: I have been using Postgres with PostGIS for a few months now, and
Edit: Updating post based on Martins comments below Hello, I'm just trying to get
EDIT: changed the whole question sorry, im trying to deal with the mysql DATETIME
EDIT: I am using MS SQL server 2008 R2 as well. Well, on a
EDIT: I'm using MySQL, I found another post with the same question, but it's
EDIT: I simplified the example to use text inputs. Same error. Form fails to
Edit Using the answers to the question I changed the test to the following
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT: I was an idiot. I simply had an image that was vertically long,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.