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

  • Home
  • SEARCH
  • 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 6862757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:42:00+00:00 2026-05-27T02:42:00+00:00

I need to invert a BigInteger . Let’s say i have BigInteger x; and

  • 0

I need to invert a BigInteger.

Let’s say i have BigInteger x; and i need to calculate x.modPow(new BigInteger("-1"), p).

I receive the following error: java.lang.ArithmeticException: BigInteger not invertible.

  • 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-05-27T02:42:01+00:00Added an answer on May 27, 2026 at 2:42 am

    Use BigInteger.modInverse() — it will do what you want.

    If you read the docs for BigInteger.modInverse() (which performs the identical calculation, but more efficiently than your code; in fact presumably BigInteger.modPow() calls modInverse() for negative inputs before raising to a power), you’ll see:

    Throws: ArithmeticException – m <= 0, or this BigInteger has no multiplicative inverse mod m (that is, this BigInteger is not relatively prime to m).

    If you’re getting “BigInteger not invertible” this means that x and p are not relatively prime, so there is no mathematically defined inverse for the pair of numbers x and p given as input.

    Possibilities:

    • p is prime, and x is 0 or a multiple of p
    • p is not prime, and x and p have a common factor
    • p is not a positive integer (0 or negative), which violates the requirements of modPow() and modInverse()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a Fraction class: class Fraction { ... /** Invert current
I have the following configuration: <div><div id='box1'>&nbsp;</div><div id='box2'>&nbsp;</div><div id='box3'>&nbsp;</div><div id='box4'>&nbsp;</div></div> what i need to
I'm trying to calculate the inverse matrix in Java. I'm following the adjoint method
Let's say I have a class Voucher: public class Voucher { public Guid Id
I'm an absolute beginner, and I need to have a button to invert two
I need to invert a dictionary of lists, I don't know how to explain
I have a two dimensional array that I need to rotate 90 degrees clockwise,
So below I have a code in C++ that is supposed to invert the
We have a project using LINQ to SQL, for which I need to rewrite
I need to track a number of ajax-actions on my site and I have

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.