public static void testICDE() { // Number of total operations int numberOfTests = 5; // Length of the p, note that n=p.q int lengthp = 512; Paillier esystem = new Paillier(); Random rd = new Random(); PaillierPrivateKey key = KeyGen.PaillierKey(lengthp, 122333356); esystem.setDecryptEncrypt(key); // let's test our algorithm by encrypting and decrypting few instances long start = System.currentTimeMillis(); for (int i = 0; i < numberOfTests; i++) { BigInteger m1 = BigInteger.valueOf(Math.abs(rd.nextLong())); BigInteger m2 = BigInteger.valueOf(Math.abs(rd.nextLong())); BigInteger c1 = esystem.encrypt(m1); BigInteger c2 = esystem.encrypt(m2); BigInteger c3 = esystem.multiply(c1, m2); c1 = esystem.add(c1, c2); c1 = esystem.add(c1, c3); esystem.decrypt(c1); } long stop = System.currentTimeMillis(); System.out.println( "Running time per comparison in milliseconds: " + ((stop - start) / numberOfTests)); }
void solve(InputReader in) { try { long start = System.currentTimeMillis(); F[0] = BigInteger.ONE; for (i = 1; i <= 30; ++i) F[i] = F[i - 1].multiply(BigInteger.valueOf(i)); for (i = 1; i <= 30; ++i) { for (j = 1; j <= i; ++j) { C[i][j] = getResult(i, j); } } t = in.nextInt(); while (t-- > 0) { for (i = 1; i <= 30; ++i) g[i] = new ArrayList(); n = in.nextInt(); for (i = 1; i <= n; ++i) a[i] = in.nextInt(); root = a[1]; p = 2; Construct(root, 1, 30); Pair ans = Calculate(root); System.out.println(ans.x); } long end = System.currentTimeMillis(); if (time) System.out.println("Execution time: " + (double) (end - start) / 1000.0); } catch (Exception e) { System.out.println("Error: " + e); } ; }
// BEGIN KAWIGIEDIT TESTING // Generated by KawigiEdit 2.1.8 (beta) modified by pivanof private static boolean KawigiEdit_RunTest( int testNum, int p0, int p1, boolean hasAnswer, String p2) { System.out.print("Test " + testNum + ": [" + p0 + "," + p1); System.out.println("]"); KLastNonZeroDigits obj; String answer; obj = new KLastNonZeroDigits(); long startTime = System.currentTimeMillis(); answer = obj.getKDigits(p0, p1); long endTime = System.currentTimeMillis(); boolean res; res = true; System.out.println("Time: " + (endTime - startTime) / 1000.0 + " seconds"); if (hasAnswer) { System.out.println("Desired answer:"); System.out.println("\t" + "\"" + p2 + "\""); } System.out.println("Your answer:"); System.out.println("\t" + "\"" + answer + "\""); if (hasAnswer) { res = answer.equals(p2); } if (!res) { System.out.println("DOESN'T MATCH!!!!"); } else if ((endTime - startTime) / 1000.0 >= 2) { System.out.println("FAIL the timeout"); res = false; } else if (hasAnswer) { System.out.println("Match :-)"); } else { System.out.println("OK, but is it right?"); } System.out.println(""); return res; }
// BEGIN KAWIGIEDIT TESTING // Generated by KawigiEdit-pf 2.3.0 private static boolean KawigiEdit_RunTest(int testNum, int p0, boolean hasAnswer, int p1) { System.out.print("Test " + testNum + ": [" + p0); System.out.println("]"); EmoticonsDiv1 obj; int answer; obj = new EmoticonsDiv1(); long startTime = System.currentTimeMillis(); answer = obj.printSmiles(p0); long endTime = System.currentTimeMillis(); boolean res; res = true; System.out.println("Time: " + (endTime - startTime) / 1000.0 + " seconds"); if (hasAnswer) { System.out.println("Desired answer:"); System.out.println("\t" + p1); } System.out.println("Your answer:"); System.out.println("\t" + answer); if (hasAnswer) { res = answer == p1; } if (!res) { System.out.println("DOESN'T MATCH!!!!"); } else if ((endTime - startTime) / 1000.0 >= 2) { System.out.println("FAIL the timeout"); res = false; } else if (hasAnswer) { System.out.println("Match :-)"); } else { System.out.println("OK, but is it right?"); } System.out.println(""); return res; }
public static void main(String[] args) { if (args.length < 5) { System.out.println( "\n Usage: java prob.mdp.MDPSim prob_file " + "spudd_vfun trials steps rand_seed\n"); System.exit(1); } MDPSim mdpsim = new MDPSim(args[0], args[1]); ArrayList vals = null; int trials = -1, steps = -1; long seed = -1; try { trials = Integer.parseInt(args[2]); steps = Integer.parseInt(args[3]); seed = Long.parseLong(args[4]); vals = mdpsim.simulate(trials, steps, seed); } catch (NumberFormatException nfe) { System.out.println(nfe); System.exit(1); } System.out.println("\n Problem: " + args[0]); System.out.println(" VFun: " + args[1]); System.out.println(" Trials: " + trials); System.out.println(" Steps: " + steps); System.out.println(" Seed: " + seed); System.out.println(" Data: " + PrintList(vals)); System.out.println(" Average: " + MDP._df.format(Average(vals)) + "\n"); }
public static void main(String args[]) { try { System.setIn(new FileInputStream("vans.in")); System.setOut(new PrintStream("vans.out")); } catch (Throwable T_T) { } new vans().run(); }
private static void setStream(String in, String out) { try { System.setIn(new BufferedInputStream(new FileInputStream(in))); System.setOut(new PrintStream(out)); } catch (Exception e) { e.printStackTrace(); } }
// BEGIN KAWIGIEDIT TESTING // Generated by KawigiEdit 2.1.4 (beta) modified by pivanof private static boolean KawigiEdit_RunTest( int testNum, int[] p0, int[] p1, int[] p2, boolean hasAnswer, int p3) { System.out.print("Test " + testNum + ": [" + "{"); for (int i = 0; p0.length > i; ++i) { if (i > 0) { System.out.print(","); } System.out.print(p0[i]); } System.out.print("}" + "," + "{"); for (int i = 0; p1.length > i; ++i) { if (i > 0) { System.out.print(","); } System.out.print(p1[i]); } System.out.print("}" + "," + "{"); for (int i = 0; p2.length > i; ++i) { if (i > 0) { System.out.print(","); } System.out.print(p2[i]); } System.out.print("}"); System.out.println("]"); KeyDungeonDiv2 obj; int answer; obj = new KeyDungeonDiv2(); long startTime = System.currentTimeMillis(); answer = obj.countDoors(p0, p1, p2); long endTime = System.currentTimeMillis(); boolean res; res = true; System.out.println("Time: " + (endTime - startTime) / 1000.0 + " seconds"); if (hasAnswer) { System.out.println("Desired answer:"); System.out.println("\t" + p3); } System.out.println("Your answer:"); System.out.println("\t" + answer); if (hasAnswer) { res = answer == p3; } if (!res) { System.out.println("DOESN'T MATCH!!!!"); } else if ((endTime - startTime) / 1000.0 >= 2) { System.out.println("FAIL the timeout"); res = false; } else if (hasAnswer) { System.out.println("Match :-)"); } else { System.out.println("OK, but is it right?"); } System.out.println(""); return res; }
static { try { System.loadLibrary("primitive_ref"); } catch (UnsatisfiedLinkError e) { System.err.println( "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); System.exit(1); } }
public static void main(String[] args) { long start = System.currentTimeMillis(); while (in.hasNext()) solve(); out.flush(); long end = System.currentTimeMillis(); // trace(end-start + "ms"); in.close(); out.close(); }
public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); solve(); out.flush(); long end = System.currentTimeMillis(); // trace(end-start + "ms"); br.close(); out.close(); }
public static void main(String[] args) { debug = args.length > 0; long start = System.currentTimeMillis(); solve(); out.flush(); long end = System.currentTimeMillis(); dump((end - start) + "ms"); in.close(); out.close(); }
public static void main(String[] args) { debug = args.length > 0; long start = System.nanoTime(); solve(); out.flush(); long end = System.nanoTime(); dump((end - start) / 1000000 + " ms"); in.close(); out.close(); }
@Override public Item item(final QueryContext qc, final InputInfo ii) throws QueryException { final B64 b64 = toB64(exprs[0], qc, true); long by = toLong(exprs[1], qc); if (b64 == null) return null; if (by == 0) return b64; byte[] bytes = b64.binary(info); final int bl = bytes.length; byte[] tmp = new byte[bl]; int r = 0; if (by > 7) { tmp = new BigInteger(bytes).shiftLeft((int) by).toByteArray(); if (tmp.length != bl) { bytes = tmp; tmp = new byte[bl]; System.arraycopy(bytes, bytes.length - bl, tmp, 0, bl); } } else if (by > 0) { for (int i = bl - 1; i >= 0; i--) { final byte b = bytes[i]; tmp[i] = (byte) (b << by | r); r = b >>> 32 - by; } } else if (by > -8) { by = -by; for (int i = 0; i < bl; i++) { final int b = bytes[i] & 0xFF; tmp[i] = (byte) (b >>> by | r); r = b << 32 - by; } } else { by = -by; BigInteger bi = new BigInteger(bytes); if (bi.signum() >= 0) { bi = bi.shiftRight((int) by); } else { final BigInteger o = BigInteger.ONE.shiftLeft(bl * 8 + 1); final BigInteger m = o.subtract(BigInteger.ONE).shiftRight((int) by + 1); bi = bi.subtract(o).shiftRight((int) by).and(m); } tmp = bi.toByteArray(); final int tl = tmp.length; if (tl != bl) { bytes = tmp; tmp = new byte[bl]; System.arraycopy(bytes, 0, tmp, bl - tl, tl); } } return new B64(tmp); }
public static void main(String[] args) { long start = System.currentTimeMillis(); Scanner input = new Scanner(System.in); int numberOfTestCases = input.nextInt(); ArrayList<Integer> order = new ArrayList<Integer>(numberOfTestCases); int previousKey = -1; int previousValue = 0; int cycleNumber = 0; Map<Integer, Integer> testCases = new TreeMap<Integer, Integer>(); for (int i = 0; i < numberOfTestCases; i++) { int numberOfCycles = input.nextInt(); testCases.put(numberOfCycles, 1); order.add(numberOfCycles); } for (Map.Entry<Integer, Integer> entry : testCases.entrySet()) { int numberOfCycles; int initialHeight; if (previousKey == -1) { numberOfCycles = entry.getKey(); initialHeight = entry.getValue(); } else { numberOfCycles = entry.getKey() - previousKey; initialHeight = previousValue; } for (int i = 0; i < numberOfCycles; i++) { if (cycleNumber % 2 == 0) { initialHeight *= 2; } else { initialHeight += 1; } cycleNumber++; } entry.setValue(initialHeight); previousKey = entry.getKey(); previousValue = initialHeight; } for (Integer element : order) { System.out.println(testCases.get(element)); } long elapsed = System.currentTimeMillis() - start; System.out.println("time: " + elapsed); }
// BEGIN KAWIGIEDIT TESTING // Generated by KawigiEdit-pf 2.3.0 private static boolean KawigiEdit_RunTest( int testNum, int[] p0, int[] p1, boolean hasAnswer, double p2) { System.out.print("Test " + testNum + ": [" + "{"); for (int i = 0; p0.length > i; ++i) { if (i > 0) { System.out.print(","); } System.out.print(p0[i]); } System.out.print("}" + "," + "{"); for (int i = 0; p1.length > i; ++i) { if (i > 0) { System.out.print(","); } System.out.print(p1[i]); } System.out.print("}"); System.out.println("]"); GreaterGame obj; double answer; obj = new GreaterGame(); long startTime = System.currentTimeMillis(); answer = obj.calc(p0, p1); long endTime = System.currentTimeMillis(); boolean res; res = true; System.out.println("Time: " + (endTime - startTime) / 1000.0 + " seconds"); if (hasAnswer) { System.out.println("Desired answer:"); System.out.println("\t" + p2); } System.out.println("Your answer:"); System.out.println("\t" + answer); if (hasAnswer) { res = answer == answer && Math.abs(p2 - answer) <= 1e-9 * Math.max(1.0, Math.abs(p2)); } if (!res) { System.out.println("DOESN'T MATCH!!!!"); } else if ((endTime - startTime) / 1000.0 >= 2) { System.out.println("FAIL the timeout"); res = false; } else if (hasAnswer) { System.out.println("Match :-)"); } else { System.out.println("OK, but is it right?"); } System.out.println(""); return res; }
public static void main(String[] args) throws Exception { if (args.length == 0) { printUsage(args.length); System.exit(0); } else { processArgsAndInitialize(args); } // non-specified args will be set to default values in processArgsAndInitialize if (candFileFormat.equals("plain")) { println("Evaluating candidate translations in plain file " + candFileName + "..."); evaluateCands_plain(candFileName); } else if (candFileFormat.equals("nbest")) { println( "Evaluating set of " + candRank + "'th candidate translations from " + candFileName + "..."); evaluateCands_nbest(candFileName, candRank); } println(""); if (evaluateRefs) { // evaluate the references themselves; useful if developing a new evaluation metric println(""); println("PERFORMING SANITY CHECK:"); println("------------------------"); println(""); println( "This metric's scores range from " + evalMetric.worstPossibleScore() + " (worst) to " + evalMetric.bestPossibleScore() + " (best)."); for (int r = 1; r <= refsPerSen; ++r) { println(""); println("(*) Evaluating reference set " + r + ":"); println(""); evaluateRefSet(r); println(""); } } System.exit(0); } // main(String[] args)
public static void main(String[] args) { try { Context ctx = new InitialContext(); Object objref = ctx.lookup(JNDI_NAME); SavingsAccountHome home = (SavingsAccountHome) PortableRemoteObject.narrow(objref, SavingsAccountHome.class); BigDecimal zeroAmount = new BigDecimal("0.00"); SavingsAccount John = home.create("100", "John", "Smith", zeroAmount); System.out.println("Account Name: " + John.getFirstName()); System.out.println("Credit: 88.50"); John.credit(new BigDecimal("88.50")); System.out.println("Debit: 20.25"); John.debit(new BigDecimal("20.25")); BigDecimal balance = John.getBalance(); System.out.println("Balance = " + balance); // John.remove(); System.exit(0); } catch (InsufficientBalanceException ex) { System.err.println("Caught an InsufficientBalanceException: " + ex.getMessage()); } catch (Exception ex) { System.err.println("Caught an exception."); ex.printStackTrace(); } }
public PrepartitionSolution(long[] input) { generator = new Random(System.nanoTime()); sequence = input; sol = new int[input.length]; randomizeSolution(); // sol[0] = 0; sol[1] = 1; sol[2] = 1; sol[3] = 3; sol[4] = 4; }
/** * Set Measure Actual * * @param MeasureActual actual */ @Override public void setMeasureActual(BigDecimal MeasureActual) { if (MeasureActual == null) return; super.setMeasureActual(MeasureActual); setDateLastRun(new Timestamp(System.currentTimeMillis())); setGoalPerformance(); } // setMeasureActual
void pln(String s) { try { bw.write(s); bw.write(System.lineSeparator()); } catch (Exception ex) { } }
public PrepartitionSolution(PrepartitionSolution p) { sequence = p.sequence; generator = new Random(System.nanoTime()); sol = new int[p.sol.length]; for (int i = 0; i < sol.length; ++i) { sol[i] = p.sol[i]; } }
public static void main(String[] args) { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); A1Task solver = new A1Task(); solver.solve(in, out); out.close(); System.exit(0); }
public static void main(String[] args) throws IOException { // in = new BufferedReader(new InputStreamReader(System.in)); // out = new PrintWriter(new BufferedOutputStream(System.out)); String file = "C-large"; in = new BufferedReader(new FileReader(file + ".in")); out = new PrintWriter(new FileOutputStream(file + "_" + System.currentTimeMillis() + ".out")); solve(); out.flush(); }
private static void usage() { Print.logInfo("Usage:"); Print.logInfo(" java ... " + URIArg.class.getName() + " {options}"); Print.logInfo("Options:"); Print.logInfo(" -encode=<ASCII> Encode ASCII string to URL argument string"); Print.logInfo(" -decode=<args> Decode URL argument string to ASCII"); Print.logInfo(" -rtpEnc=<url> RTP Encode URL [key = 'rtp']"); Print.logInfo(" -rtpDec=<url> RTP Decode URL [key = 'rtp']"); System.exit(1); }
public static void main(String[] args) throws Exception { time = System.currentTimeMillis(); IN = System.in; OUT = System.out; in = new BufferedReader(new InputStreamReader(IN)); out = new PrintWriter(OUT, FLUSH); solveOne(); out.flush(); }
/** * Returns the date in seconds. * * @return seconds */ final BigDecimal seconds() { int z = tz; if (z == Short.MAX_VALUE) { // [CG] XQuery, DateTime: may be removed final long n = System.currentTimeMillis(); z = Calendar.getInstance().getTimeZone().getOffset(n) / 60000; } return (sec == null ? BigDecimal.ZERO : sec) .add(BigDecimal.valueOf(Math.max(0, hou) * 3600 + Math.max(0, min) * 60 - z * 60)); }
private void receiveEGTable() { int nBytes = (nBits - 1) / 8 + 1; try { for (int j = 0; j < nCols; j++) EGTable[j] = Utils.readBigInteger(nBytes * Wire.labelBitLength, ois); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
/** * Set a custom operator, replacing any existing operator with the same symbol. Operators cannot * be removed, only replaced. */ public MathEval setOperator(Operator opr) { if (opr.symbol >= operators.length) { // extend the array if necessary Operator[] noa = new Operator[opr.symbol + (opr.symbol % 255) + 1]; // use allocation pages of 256 System.arraycopy(operators, 0, noa, 0, operators.length); operators = noa; } operators[opr.symbol] = opr; return this; }
public static void main(String args[]){ String infilename = args[0]; String outfilename= args[1]; if(args.length <1 || args.length >=3){ usage(); System.exit(2); } if(!new File(infilename).exists()){ System.out.println("No such file:"+infilename); System.exit(1); } if(new File(outfilename).exists()){ //To Overwrite? } System.out.println("write:"+infilename+">"+outfilename); //@ToDo - Check arguments are valid files... CDToolParser me=new CDToolParser(infilename,outfilename); }