Created
June 28, 2013 23:34
-
-
Save tmathmeyer/5888931 to your computer and use it in GitHub Desktop.
eulers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.wpi.tmathmeyer.euler; | |
public class Probs { | |
public static void problem30(){ | |
int[] fives = new int[10]; | |
for(int i = 0; i < 10; i++) | |
{ | |
fives[i] = pow(i, 5); | |
System.out.println(fives[i]); | |
} | |
int sup = 0; | |
for(int i = 2; i < 999999; i++) | |
{ | |
int sum = 0; | |
for(int j = 0; j < (i+"").length(); j++) | |
{ | |
int digit = Integer.parseInt((i+"").charAt(j)+""); | |
sum += fives[digit]; | |
if (sum > i) | |
{ | |
j = 1324098; | |
} | |
} | |
if (sum == i && i != 59049) | |
{ | |
System.out.println("answer: "+sum); | |
sup+=sum; | |
} | |
if (i%1000 == 0) | |
{ | |
//System.out.println(i/1000 + "%"); | |
} | |
} | |
System.out.println(sup); | |
} | |
public static int pow(int a, int b) | |
{ // a^b | |
if (b==0) | |
{ | |
return 1; | |
} | |
if (b==1) | |
{ | |
return a; | |
} | |
if (b%2 == 0) | |
{ | |
return pow(a*a, b/2); | |
} | |
return a * pow (a, b-1); | |
} | |
public static void problem33() | |
{ | |
for (int num = 1; num < 100; num++) | |
{ | |
for(int dem = num+1; dem < 100; dem++) | |
{ | |
if ((num%10 == dem/10) && (dem%10 * num == (num/10) * dem)){ | |
System.out.println(num+"/"+dem); | |
} | |
} | |
} | |
} | |
public static void problem37() | |
{ | |
int[] i = new int[100000]; | |
for(int x = 2; x < 100000; x++) | |
{ | |
if (i[x] == 0) | |
{ | |
for(int k = 2*x; k < 100000; k += x) | |
{ | |
i[k] = 1; | |
} | |
if (!(x%10==7 || x%10==3)) | |
{ | |
i[x] = 1; | |
} | |
else | |
{ | |
int q = pow(10, (x+"").length()-1); | |
if (!(x/q==7 || x/q==3)) | |
{ | |
i[x] = 1; | |
} | |
} | |
} | |
} | |
for(int x = 1; x < 1000; x++) | |
{ | |
System.out.print(i[x]==0?x+"\n":""); | |
} | |
} | |
public static void main(String[] args){ | |
problem37(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment