2014.3.24
第一题(java):
public class ProjectEuler1 { public static void main(String[] args) { int a = 0; int b = 0; for(;a < 1000;a++){ if(a%3 == 0 || a%5 == 0){ b = b + a; } } System.out.println(b); } }
2014.3.26
第二题(java):
import java.util.ArrayList; class ProjectEuler2{ public static void main(String[] args){ ArrayList<Integer> arrayList = new ArrayList<Integer>(); arrayList.add(1); arrayList.add(2); int i = 0; while(arrayList.get(i) + arrayList.get(i + 1) < 4000000){ arrayList.add(arrayList.get(i) + arrayList.get(i + 1)); i++; } int b = 0; for(int a = 0;a <= (i + 1);a++){ if(arrayList.get(a)%2 == 0){ b = b + arrayList.get(a); } } System.out.println(b); } }
2014.3.27
第三题(java):
class ProjectEuler3{ public static void main(String [] args){ int integer = 2; long number = 600851475143L; int largestprimefactor = 1; for(;integer < Math.sqrt(number);integer++){ //判断integer是否是prime boolean integerisprime = false; int temp = 2; for(;temp < Math.sqrt(integer);temp++){ if(integer%temp == 0){ break; } } if(temp >= Math.sqrt(integer)){ integerisprime = true; } //如果integer是prime且整除number,把integer设为最大prime if(integerisprime == true && number%integer == 0){ largestprimefactor = integer; } } System.out.println(largestprimefactor); } }
2014.5.7
第四题(python):
largest = 0 num1 = 100 num2 = 100 def is_palindromic(temp): if temp < 100000: digit = 5 else: digit = 6 digits = [] for i in range(0, digit): digits.append((temp%(10**(i + 1)))/(10**i)) temp2 = 0 for i in range(0, digit): if digits[i] == digits[digit - i - 1]: temp2 = i else: break if i == digit - 1: return True else: return False for num1 in range(100, 1000): for num2 in range(100, 1000): temp = num1 * num2 if is_palindromic(temp): largest = max(largest, temp) print largest
2014.5.8
第五题(python):
smallest = 1 #greatest common divisor def GCD(a, b): if a % b == 0: return b else: return GCD(b, a % b) for i in range(2, 21): smallest = (smallest * i)/GCD(smallest, i) print smallest
没有评论:
发表评论