/*http://projecteuler.net/problem=28Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:21 22 23 24 2520 7 8 9 1019 6 1 2 1118 5 4 3 1217 16 15 14 13It can be verified that the sum of the numbers on the diagonals is 101.What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?================3x3: don't sum (3-2), then sum5x5: don't sum (5-2), then sum7x7: don't sum (7-2), then sum...============*/public class Problem28{ long sum = 1; int matrix = 1001; long max = (matrix * matrix) + 1; int m = 3; int k = 0; public static void main(String[] args) { new Problem28().solve(); } public void solve() { for(long x = 2; x < max; x++) { if(k < (m-2)) { k++; continue; } sum += x; k = 0; if((m*m) == x) m += 2; } System.out.println(sum); }} #outer-wrapper { margin: 0px; margin-left: 100px; }#content-wrapper { width: 1000px; }#main-wrapper { width: 600px;}Go here to read the problem statement:http://community.topcoder.com/stat?c=problem_statement&pm=3080&rd=6518Java solution for problem Cafeteria, from TopCoder:public class Cafeteria{ int sx, sy; int T = 14 * 60 + 30; int q, r; public String latestTime(int[] offset, int[] walkingTime, int[] drivingTime) { int N = offset.length; int[] times = new int[N]; int maxTime = Integer.MIN_VALUE, idx = -1; for(int i = 0; i < N; i++) { int temp = Math.abs(T - drivingTime[i]); int q = temp / 60; int r = temp % 60; for(int o = 50 + offset[i]; ; o -= 10) if(o <= r) { temp = (o + q * 60) - walkingTime[i]; break; } times[i] = temp; if(times[i] > maxTime) { maxTime = times[i]; idx = i; } } q = times[idx] / 60; if(q > 12) q -= 12; r = times[idx] % 60; String sq = (q < 10) ? "0"+q : ""+q; String sr = (r < 10) ? "0"+r : ""+r; return sq + ":" + sr; } public static void main(String[] args) { Cafeteria c = new Cafeteria(); int[] offset = {9}; int[] walkingTime = {1}; int[] drivingTime = {1}; System.out.println(c.latestTime(offset, walkingTime, drivingTime)); System.out.println(c.latestTime( new int[]{6}, new int[]{9}, new int[]{120})); System.out.println(c.latestTime( new int[]{6,9}, new int[]{9,10}, new int[]{120,121})); System.out.println(c.latestTime( new int[]{0,1,2,3,4,5,6,7,8,9}, new int[]{11,11,11,11,11,11,11,11,11,11}, new int[]{190,190,190,190,190,190,190,190,190,190})); System.out.println(c.latestTime( new int[]{7,4,0,0,2,1,6,7,7,0,8,6,0,5,0,6,7,9,0,2,4,8,4,7,9,2,4,4,3,1,4,5,8,8,2,5,7,8,7,5,6,8,8,0,1,3,5,0,8}, new int[]{26,14,1,4,16,28,16,6,4,5,21,18,5,2,21,21,28,22,5,22,26,16,14,19,19,19,4,12,24,4,30,16,28,20,25,2,30,18,4,6,9,22,8,3,7,29,8,30,6}, new int[]{151,264,280,89,63,57,15,120,28,296,76,269,90,106,31,222,291,52,102,73,140,248,44,187,76,49,296,106,54,119,54,283,263,285,275,127,108,82,84,241,169,203,244,256,109,288,9,262,103})); }} #outer-wrapper { margin: 0px; margin-left: 100px; }#content-wrapper { width: 1000px; }#main-wrapper { width: 600px;}Solution for problem BatchSystem, used in Single Round Match 481 Round 1 - Division II, Level ThreeProblem statement:http://community.topcoder.com/stat?c=problem_statement&pm=10808&rd=14234I used permutation code from:http://www.cs.utexas.edu/users/djimenez/utsa/cs3343/lecture25.htmlSRM 481 - TopCoder Wiki:http://apps.topcoder.com/wiki/pages/viewpage.action?pageId=45188543&navigatingVersions=true /*http://projecteuler.net/problem=10The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.Find the sum of all the primes below two million.*/class Problem10{ int[] primes = new int[3000000]; int primeCount = 0; long sum = 0; public static void main(String[] args) { new Problem10().solve(); } public void solve() { sum += 2; primes[primeCount] = 2; primeCount++; for(int i = 3; i < 2000000; i++) { if(isPrime(i)) { sum += i; primes[primeCount] = i; primeCount++; }