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 7876237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:08:14+00:00 2026-06-03T03:08:14+00:00

Another BigInteger problem. My code works for int and long, but since the test

  • 0

Another BigInteger problem. My code works for int and long, but since the test cases in UVa are larger, I need to use BigInteger. But I don’t know how to use BigInteger and it drives me nuts! The code doesn’t even enter the for-loop. It seems to be stuck in the condition part.
I tried using for or while, and they have the same problem.

public class Main{
  public static void main(String[] asdf){
    Scanner pp = new Scanner(System.in);
    int testCases = pp.nextInt();
    while(testCases-- > 0){
      //BigInteger a = pp.nextBigInteger();
      BigInteger low = pp.nextBigInteger();
      BigInteger upp = pp.nextBigInteger();
      BigInteger  max = BigInteger.ZERO;
      BigInteger i = low;
      //((i.compareTo(upp)==-1)||
      //(i.compareTo(upp)==0));
      //i.add(BigInteger.ONE))
      while((i.compareTo(upp))<0){
        if(divCount(i).compareTo(divCount(max))==1){
          max = i;
        }
        i.add(BigInteger.ONE);
      }
      System.out.println("Between "+low+" and "+upp+", "+max+" has a maximum of "+divCount(max)+" divisors.");
    }
  }
  public static BigInteger divCount(BigInteger n){
    BigInteger lim = n;
    BigInteger size = BigInteger.ZERO;
    BigInteger i = BigInteger.ONE; 
    while(i.compareTo(lim)<0){
      if((n.mod(i).compareTo(BigInteger.ZERO))==0){
        lim = n.divide(i);
        if(!(lim.equals(i))){
          size.add(BigInteger.ONE);
        }
        size.add(BigInteger.ONE);
      }
      i.add(BigInteger.ONE);
    }
    //return size;
    return BigInteger.ONE;
  }
}
  • 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-03T03:08:15+00:00Added an answer on June 3, 2026 at 3:08 am

    i.add(BigInteger.ONE) does not modify i. Instead it returns a new object. Assign the value to i to get the effect you want. Same holds true for the other similar calls in your code.

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

Sidebar

Related Questions

another day, another problem :) Since I woke up today I'm wondering about numbers.
another sql problem of mine .. this time the reader doesn't work properly (
Another noob regex problem/question. I'm probably doing something silly so I thought I'd exploit
Another jquery calculation question. I've this, which is sample code from the plugin site
I'm doing some large integer computing, and I need to raise a BigInteger to
Another hopefully rather trivial mvcSiteMap problem: I have a few nodes that I only
Another IE6 (and 7) float problem. I've some label s at right and some
another one ive been at for hours. Im having a major problem getting my
Another question like this one was asked, but I don't 'like' the answer (in
another day, another problem. Honestly, it would be rather boring if this ever stopped,

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.