Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
project euler 12, java
//I can't believe it's just that small import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { int num = 0; for (int i = 1; ; i++) { num += i; // num is triangle number i if (countDivisors(num) > 500) { System.out.println(Integer.toString(num)); return; } } } private static int countDivisors(int n) { int count = 0; int end = (int)Math.sqrt(n); for (int i = 1; i < end; i++) { if (n % i == 0) count += 2; } if (n % end == 0) // Perfect square count++; return count; } }
run
|
edit
|
history
|
help
0
Bank System
linked lists
or You Over the hill
Test processing time (loop vs. contains)
Greedy algo Activity program
Java Object structure dumper (iterative)
Word pattern
4c
Search substring
pk2