Skip to main content

Posts

Showing posts with the label Life

Java 8 coding challenge: Life, the Universe, and Everything

Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits. SAMPLE INPUT 1 2 88 42 99 SAMPLE OUTPUT 1 2 88   Code: import java.util.*; import java.io.*; import java.math.BigInteger; public class Tester { public static long mod=(long)(1e9+7); public static long xx,yy,d; static int minPrime[]; static boolean isPrime[]; public static void main(String[] args) throws IOException { InputReader s=new InputReader(System.in); OutputStream outputStream = System.out; PrintWriter out=new PrintWriter(outputStream); while(true) { int n=s.nextInt(); if(n==42) break; else out.println(n); } out.close(); } static void modifiedSieve(int n) { minPrime = new int[n+1]; for(int i=2; i<=Math.sqrt(n); i++) { if(minPrime[i] == 0) {...

Java 8 coding challenge: Life, the Universe, and Everything

Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits. SAMPLE INPUT 1 2 88 42 99 SAMPLE OUTPUT 1 2 88 Code: import java.util.*; import java.io.*; import java.math.BigInteger; public class Tester { public static long mod=(long)(1e9+7); public static long xx,yy,d; static int minPrime[]; static boolean isPrime[]; public static void main(String[] args) throws IOException { InputReader s=new InputReader(System.in); OutputStream outputStream = System.out; PrintWriter out=new PrintWriter(outputStream); while(true) { int n=s.nextInt(); if(n==42) break; else out.println(n); } out.close(); } static void modifiedSieve(int n) { minPrime = new int[n+1]; for(int i=2; i<=Math.sqrt(n); i++) { if(minPrime[i] == 0) { for(int j=i*i; j<=n...