Commits

Shlomi Fish committed fc7075d

Add more.

Comments (0)

Files changed (2)

project-euler/78/78-2.pl

 use 5.010;
 
 use List::Util qw(sum min);
-use Math::BigInt (":constant", lib => 'GMP');
+# use Math::BigInt (":constant", lib => 'GMP');
+use integer;
 
 STDOUT->autoflush(1);
 
     }
     else
     {
-        return ($p[$n][$k] ||= (p_k_n($k+1, $n) + p_k_n($k,$n-$k)));
+        return ($p[$n][$k] ||= ((p_k_n($k+1, $n) + p_k_n($k,$n-$k)) % 1_000_000));
     }
 }
 
 {
     my $p = p_k_n(1, $n);
     print "N = $n ; V = $p\n";
-    if ($p % 1_000_000 == 0)
+    if ($p % 10000 == 0)
     {
         last N_LOOP;
     }
 {
     $n++;
 }
+
+# For % 1,000 == 449
+# For % 100 = 74
+# For % 10 = 9

project-euler/78/Problem78.java

+public class Problem78 {
+	static int[] p = new int[1000000];
+ 
+	static int penta(int n){
+		return n*(3*n -1)/2;
+	}
+ 
+	static int sign(int k){
+		return (k+1 & 2) - 1;
+	}
+ 
+	public static void main(String[] args){
+		p[0] = 1;
+		int n = 1;
+		while(p[n-1]%1000000 != 0){			
+			int x = 1;
+			int i = 1;
+			p[n] = 0;
+ 
+			while(penta(x) <= n){							
+				p[n] = p[n] + p[n - penta(x)]*sign(i);
+				p[n] = p[n] % 1000000;
+				if(x > 0) x = -x;
+				else x = (-x) + 1;
+				i++;
+			}			
+			n++;
+		}		
+		System.out.println(n-1);
+	}
+}