public static boolean check(long n, int p) { BigInteger P = BigInteger.TEN.pow(p), Q = BigInteger.TEN.pow(p - 1); BigInteger N = BigInteger.ONE, tmp = BigInteger.valueOf(2); while (n > 0) { if ((n % 2) == 1) { N = N.multiply(tmp); N = N.mod(P); } tmp = tmp.multiply(tmp); tmp = tmp.mod(P); n >>= 1; } N = N.divide(Q); if (N.equals(BigInteger.ONE) || N.equals(BigInteger.valueOf(2))) return true; else return false; }
public static void main(String args[]) throws Exception { Scanner cin = new Scanner(System.in); BigInteger s, M; int p, i; while (cin.hasNext()) { p = cin.nextInt(); s = BigInteger.valueOf(4); M = BigInteger.ONE; M = M.shiftLeft(p).subtract(BigInteger.ONE); for (i = 0; i < p - 2; ++i) { s = s.multiply(s).subtract(BigInteger.valueOf(2)); while (s.bitLength() > p) { s = s.shiftRight(p).add(s.and(M)); } } if (s.compareTo(BigInteger.ZERO) == 0 || s.compareTo(M) == 0) { System.out.println(0); continue; } String ans = ""; while (s.compareTo(BigInteger.ZERO) > 0) { long buf = s.mod(BigInteger.valueOf(16)).longValue(); ans += Integer.toHexString((int) buf); s = s.divide(BigInteger.valueOf(16)); } for (i = ans.length() - 1; i >= 0; --i) System.out.print(ans.charAt(i)); System.out.println(); } }
public static void main(String[] args) { Scanner in = new Scanner(System.in); n = in.nextInt(); l = new BigInteger(in.next()); k = in.nextInt(); m = in.nextInt(); BigInteger w = BigInteger.TEN.pow(m); for (int i = 0; i <= n; ++i) a[i] = new BigInteger(in.next()); for (int i = 0; i < Math.min(k, n + 1); ++i) { t = a[0]; for (int j = 1; j <= n; ++j) { t = t.multiply(l); t = t.add(a[j]); } t = t.mod(w); q[n][i] = t.mod(w); int ret = 0; c = t.toString().toCharArray(); int ll = c.length; for (int j = 0; j < Math.min(m, ll); ++j) { ret += (c[ll - 1 - j] - '0') * (c[ll - 1 - j] - '0'); } System.out.println(ret); l = l.add(BigInteger.ONE); } if (k > n) { for (int i = n - 1; i >= 0; --i) { for (int j = 0; j <= i; j++) q[i][j] = q[i + 1][j + 1].subtract(q[i + 1][j]).mod(w); } for (int i = 1; i <= n; ++i) q[0][i] = q[0][0]; int po = 1; for (int i = n + 1; i < k; ++i) { for (int j = 1; j <= n; ++j) q[j][(po + j) % (n + 1)] = q[j - 1][(po + j - 1) % (n + 1)].add(q[j][(po + j - 1) % (n + 1)]).mod(w); int ret = 0; c = q[n][(po + n) % (n + 1)].mod(w).toString().toCharArray(); int ll = c.length; for (int j = 0; j < Math.min(m, ll); ++j) { ret += (c[ll - 1 - j] - '0') * (c[ll - 1 - j] - '0'); } System.out.println(ret); l = l.add(BigInteger.ONE); ++po; } } }
public static void num(String str) { BigInteger a = new BigInteger(str); StringBuffer sb = new StringBuffer(""); StringBuffer n = new StringBuffer(""); while (!(a.divide(div).equals(zero))) { sb.insert(0, (char) (a.mod(div).intValue() + 96)); a = a.divide(div); } sb.insert(0, (char) (a.intValue() + 96)); for (int i = 0; i < str.length(); i++) { if (i % 3 == 0 && i != 0) n.insert(0, ","); n.insert(0, str.charAt(str.length() - i - 1)); } while (sb.length() < 22) sb.append(" "); System.out.println(sb + "" + n); }
public static void main(String args[]) { int t; Scanner s = new Scanner(System.in); t = s.nextInt(); BigInteger b1 = new BigInteger("0"); int b2; BigInteger b3 = new BigInteger("0"); BigInteger b4 = new BigInteger("10"); while (t > 0) { b1 = s.nextBigInteger(); b2 = s.nextInt(); b3 = b1.pow(b2); System.out.println(b3.mod(b4)); t--; } s.close(); }
public String getKDigits(int N, int K) { BigInteger ret = new BigInteger("1"); BigInteger ten = new BigInteger("10"); for (int i = 1; i <= N; i++) { ret = ret.multiply(new BigInteger(new Integer(i).toString())); } System.out.println(ret); while (ret.mod(ten).equals(BigInteger.ZERO)) ret = ret.divide(ten); String ans = ret.toString(); if (ans.length() > K) { ans = ans.substring(ans.length() - K, ans.length()); } return ans; }