Skip to content

Instantly share code, notes, and snippets.

View cschlisner's full-sized avatar
💣
:(){ :|:& };:

C S cschlisner

💣
:(){ :|:& };:
  • Colorado
View GitHub Profile
class q1 {
public static void main(String args[]){
int n = Integer.valueOf(args[0]);
int upperBound5 = ((n%5==0)?(n/5)-1:n/5), upperBound3 = ((n%3==0)?(n/3)-1:n/3), total=0;
for (int i=1; i<=((upperBound5>upperBound3)?upperBound5:upperBound3); ++i)
total += (((i*((upperBound5>=i)?5:0)))+(i*((upperBound3>=i)?3:0)));
System.out.println(upperBound5+" "+upperBound3+" "+total);
}
}
class q4 {
public static void main(String args[]){
int i;
boolean yep=false;
for (i=998001; i>10000; --i){
if (reverse(i)!=i)
continue;
else {
for (int j=999; j>=100; --j)
if (i%j==0 && 999>i/j && i/j>100){
class q8 {
public static void main(String args[]){
String n = "73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557668966489504452445231617318564030987111217223831136222989342338030813533627661428280644448664523874930358907296290491560440772390713810515859307960866701724271218839987979087922749219016997208880937766572733300105336788122023542180975125454059475224352584907711670556013604839586446706324415722155397536978179778461740649551492908625693219784686224828397224137565705605749026140797296865241453510047482166370484403199890008895243450658541227588666881164271714799244429282308634656748139191231628245861786645835912456652947654568284891288314260769004224219022671055626321111109370544217506941658960408071984038509624554443629812309878799272442849091888458015616609791913387549920052406368991256071760605886116467109405077541002256983155200055935729725
import tools.*;
class q10{
public static void main(String args[]){
int sum = 0;
sieve s = new sieve(2000000);
int[] a = s.getPrimes();
for (int i : a)
sum += i;
System.out.println(sum); // 1876609501
}
package tools;
public class sieve{
private int n;
public sieve(int i){
n = i+1;
}
public int[] getPrimes(){
int[] p = new int[n];
int[] result;
class q11 {
public static void main(String args[]){
int[][] map = new int[][] {{8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8},{49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0},{81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 3, 49, 13, 36, 65},{52, 70, 95, 23, 4, 60, 11, 42, 69, 24, 68, 56, 1, 32, 56, 71, 37, 2, 36, 91},{22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80},{24, 47, 32, 60, 99, 3, 45, 2, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50}, {32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70},{67, 26, 20, 68, 2, 62, 12, 20, 95, 63, 94, 39, 63, 8, 40, 91, 66, 49, 94, 21},{24, 55, 58, 5, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72},{21, 36, 23, 9, 75, 0, 76, 44, 20, 45, 35, 14, 0, 61, 33, 97, 34, 31, 33, 95},{78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 3, 80, 4, 62, 16, 14, 9, 53, 56, 92},{16, 39, 5, 42, 96, 35, 31, 47, 55, 58, 88, 2
package tools;
import java.math.*;
public class sieve{
private int n;
public sieve(int i){
n = i+1;
}
public int[] getPrimes(){
if (n==3) return new int[]{2};
project euler question 3 600851475143
hahaha
import java.io.*;
import java.util.Scanner;
class timeCalc {
private static class Time {
public int seconds, minutes, hours;
public int total = 0 ;
public Time(String t){
t = ":"+t; //format is now :hh:mm:ss, :mm:ss, or :ss
int multiplier = 1;
if (in.length() == 2)
in = "p"+in;
String[] tokens = in.split("");
String pieceSymbol = tokens[0];
int rank = -1, file = -1;
//[piece][rank OR file][destination] (e.g. Bfg6)
if (tokens.length == 4){