Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class P45 {
- public static void main(String[] args) {
- long H = 0;
- long i = 144;
- while(true) {
- H = i*((i<<1)-1);
- if ( isPentagonal(H) && isTriangle(H) ) {
- break;
- }
- i++;
- }
- System.out.println(H);
- }
- private static boolean isPentagonal(long x) {
- double n = (1 + Math.sqrt(24*x+1)) / 6;
- return n == (long)n;
- }
- private static boolean isTriangle(long x) {
- double n = (-1 + Math.sqrt((x<<3)+1)) / 2;
- return n == (long)n;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement