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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:17:10+00:00 2026-06-07T06:17:10+00:00

Possible Duplicate: Project Euler Problem 12 – C++ I am trying to get the

  • 0

Possible Duplicate:
Project Euler Problem 12 – C++

I am trying to get the first triangle number with more than 400 divisors (Triangle Number eg: 1,3,6,10). For an example, triangle number 6 has four divisors 1,2,3,6. The following is my attempt to get the triangle number with 400 divisors

import java.math.BigInteger;

public class IQ3
{

        static int num1 = 1;    
        static int devideResult = 0;      

    public static void main(String[]args)
    {


        while(true)
        {
            int triangle = num1*(num1+1)/2;

            if(devide(triangle))
            {
                break;
            }

            num1++;
        }

    }

    static boolean devide(int num)
    {
        boolean result = false;
        int devideCounter = 2;       


        for(int i=1;i<=num/2;i++)
            {
                if(num%i == 0)
                {
                    devideCounter++;
                    System.out.println("Devide Counter: "+devideCounter);
                    //System.out.println("i number: "+i);
                    //System.out.println("input number: "+num);

                    if(devideCounter>400)
                    {
                        System.out.println("Number: "+num);
                        result = true;
                        break;
                    }
                }
            }

        return result;
    }
}

But this takes a huge time, and some times it crashes.

However, since the answer could be really big, I thought of using BigInteger.

import java.math.BigInteger;

public class IQ2P2
{

        static BigInteger num1 = new BigInteger("1");
        static BigInteger two = new BigInteger("2");
        static BigInteger one = new BigInteger("1");
        static BigInteger i = new BigInteger("1");
        static BigInteger zero = new BigInteger("0");


        static int devideResult = 0;        
    //    static int devideCounter = 0;

    public static void main(String[]args)
    {


        while(true)
        {
            BigInteger triangle = num1.multiply(num1.add(one)).divide(two);

            if(devide(triangle))
            {
                break;
            }

            num1.add(one);
        }

    }

    static boolean devide(BigInteger num)
    {
        boolean result = false;
        int devideCounter = 2;       


        while((i.compareTo(num))<(num.divide(two).intValue()))
            {
                if(num.remainder(i) == zero)
                {
                    devideCounter++;
                    System.out.println("Devide Counter: "+devideCounter);
                    //System.out.println("i number: "+i);
                    //System.out.println("input number: "+num);

                    if(devideCounter>400)
                    {
                        System.out.println("Number: "+num);
                        result = true;
                        break;
                    }
                }
                i.add(one);
            }

        return result;
    }
}

But the biginteger one never returned anything.

Please help me to get first Triangle number with more than 400 divisors.

Note: This is not a homework. I am not a student.

The following is a response to an answer

import java.math.BigInteger;

public class IQ2
{

        static long num1 = 1;
        static long numberToAdd = 0;
        static long devideResult = 0;  


       static   long triangleNum = 1;
    static long incrementer = 2;
    //    static int devideCounter = 0;

    public static void main(String[]args)
    {


        while(true)
        {
            triangleNum += incrementer++;

            if(devide(triangleNum))
            {
                break;
            }

            num1++;
        }

    }

    static boolean devide(long num)
    {
        boolean result = false;
        int devideCounter = 2;       


        for(long i=1;i<=num/2;i++)
            {
                if(num%i == 0)
                {
                    devideCounter++;
                    System.out.println("Devide Counter: "+devideCounter);
                    //System.out.println("i number: "+i);
                    //System.out.println("input number: "+num);

                    if(devideCounter>400)
                    {
                        System.out.println("Number: "+num);
                        result = true;
                        break;
                    }
                }
            }

        return result;
    }
}
  • 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-07T06:17:12+00:00Added an answer on June 7, 2026 at 6:17 am

    you need to optimize the way you find out the amount of divisors for a given number. First, for every d <= sqrt(n) such that n%d==0, there is m=n/d such that n%m==0 and m >= sqrt(n). That means you can count both of them at once, stopping at sqrt(n).

    But the real optimization is to calculate the prime factorization of a number instead, and find out the amount of divisors from there.

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

Sidebar

Related Questions

Possible Duplicate: Project Euler, Problem 10 java solution not working So, I'm attempting to
Possible Duplicate: Need help solving Project Euler problem 200 Similar to this question Project
Possible Duplicate: PHP REGEX: Get domain from URL I am working on a project
Possible Duplicate: How to get random record from MS Access database In my project
Possible Duplicate: No generated R.java file in my project I am trying to run
Possible Duplicate: compiling project with jdk1.5 using maven2 I am trying to build java
Possible Duplicate: Using Git with an existing Xcode project Setting up a git repository
Possible Duplicate: R.java Missing in Android Project in NetBeans In Android I am Getting
Possible Duplicate: cmake is not working in opencv c++ project I have a huge
Possible Duplicate: Embedded a *.exe into a dll I have a C# project -

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.