We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

# Project Euler #12: Highly divisible triangular number

# Project Euler #12: Highly divisible triangular number

mtarekcse1 + 0 comments hint : if the prime factors of a number is a^n , b^m , c^q then the number of divisors is (n+1)

*(m+1)*(q+1)

empty_life + 0 comments well , all hint i can give u is for n =1000 , we have 842161320 as our triangular number which is ( (41040)*(41040 +1))/2

Umasou + 0 comments I was confused by the contest requirement. When N = 7, the right answer is 36, which has #9 factors, however 66 has #8 factors, because 66 has less factors than 36, I ordered triangle numbers by their factor numbers and kept getting the wrong answer.

I am writing this in case someone has the same misunderstanding.

anuraggupta14_11 + 0 comments MY JAVA CODE PASSES 100% TEST CASES..ENJOY

import java.io.*; import java.util.*; import java.math.*; public class Solution { static int factor(int a){ int count=0; if(a==1){ return 1; } for(int i=1;i<Math.ceil(Math.sqrt(a));i++){ if(a%i==0){ count+=2; } } if((Math.ceil(Math.sqrt(a)))==Math.floor(Math.sqrt(a))){ count++; } return count; } public static void main(String[] args) { int arr[] = new int[1001]; int temp=0,box=0; for(int i=1;i<=1000;i++){ while(temp<=i){ box++; temp=factor(((box)*(box+1))/2); } arr[i]=((box)*(box+1))/2; } Scanner sc = new Scanner(System.in); int test = sc.nextInt(); while(test-->0){ int n=sc.nextInt(); System.out.println(arr[n]); } } }

hengliustudy + 0 comments I always get time out on #6 and #7, any hints?

Load more conversations

Sort 97 Discussions, By:

Please Login in order to post a comment