Submission #857106


Source Code Expand

Copy
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;

public class Main {
	InputStream is;

	int __t__ = 1;
	int __f__ = 0;
	int __FILE_DEBUG_FLAG__ = __f__;
	String __DEBUG_FILE_NAME__ = "src/C1";

	FastScanner in;
	PrintWriter out;

	long f(long b, long n) {
		if (n < b) return n;
		return f(b, (long)Math.floor(n / b)) + n % b;
	}
	public void solve() {
		long n = in.nextLong(), s = in.nextLong();
		
		long INF = (long) 1L << 15;
		if (n < s) {
			System.out.println(-1);
		} else if ((n + 1) / 2 <= s && s < n) {
			System.out.println(-1);
		} else if (s == n) {
			System.out.println(INF);
		} else {
			System.out.println(n - s + 1);
		}
		/*
		for (int b = 2; b <= 100; b++) {
			System.out.println(b + " : " + f(b, n));
		}
		*/
		out.close();
	}

	public void run() {
		if (__FILE_DEBUG_FLAG__ == __t__) {
			try {
				is = new FileInputStream(__DEBUG_FILE_NAME__);
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
			System.out.println("FILE_INPUT!");
		} else {
			is = System.in;
		}
		in = new FastScanner(is);
		out = new PrintWriter(System.out);

		Thread t = new Thread(null, new Runnable() {
			
			@Override
			public void run() {
				solve();
			}
		}, "lul", 1 << 27);
		t.start();
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

	class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();

			return array;
		}

		int[][] nextIntMap(int n, int m) {
			int[][] map = new int[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextIntArray(m);
			}
			return map;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();

			return array;
		}

		long[][] nextLongMap(int n, int m) {
			long[][] map = new long[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextLongArray(m);
			}
			return map;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();

			return array;
		}

		double[][] nextDoubleMap(int n, int m) {
			double[][] map = new double[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextDoubleArray(m);
			}
			return map;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}


Submission Info

Submission Time
Task D - Digit Sum
User hiro116s
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 4679 Byte
Status WA
Exec Time 165 ms
Memory 8184 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
WA × 2
AC × 16
WA × 31
Set Name Test Cases
Sample subtask1_87654_30.txt, subtask1_87654_138.txt, subtask1_87654_45678.txt, subtask1_31415926535_1.txt, subtask1_1_31415926535.txt
All subtask1_100000000000_1.txt, subtask1_100000000000_100000000000.txt, subtask1_100000000000_2.txt, subtask1_100000000000_3.txt, subtask1_100000000000_50000000000.txt, subtask1_100000000000_50000000001.txt, subtask1_100000000000_99999999999.txt, subtask1_16983563041_1.txt, subtask1_1_1.txt, subtask1_1_2.txt, subtask1_1_31415926535.txt, subtask1_239484768_194586924.txt, subtask1_2_1.txt, subtask1_2_2.txt, subtask1_31415926535_1.txt, subtask1_49234683534_2461734011.txt, subtask1_4_1.txt, subtask1_58640129658_232122496.txt, subtask1_68719476735_35.txt, subtask1_68719476735_36.txt, subtask1_68719476735_37.txt, subtask1_68719476736_1.txt, subtask1_68719476736_2.txt, subtask1_72850192441_16865701.txt, subtask1_79285169301_27.txt, subtask1_82914867733_1676425945.txt, subtask1_8594813796_75700.txt, subtask1_87654_12345.txt, subtask1_87654_138.txt, subtask1_87654_30.txt, subtask1_87654_4294967308.txt, subtask1_87654_45678.txt, subtask1_97822032312_49157112.txt, subtask1_98750604051_977728851.txt, subtask1_99999515529_1.txt, subtask1_99999515529_316226.txt, subtask1_99999515529_316227.txt, subtask1_99999515529_316228.txt, subtask1_99999515529_49999757765.txt, subtask1_99999515529_49999757766.txt, subtask1_99999515530_2.txt, subtask1_99999999977_1.txt, subtask1_99999999977_2.txt, subtask1_99999999977_49999999989.txt, subtask1_99999999977_49999999990.txt, subtask1_99999999999_1.txt, subtask1_99999999999_100000000000.txt
Case Name Status Exec Time Memory
subtask1_100000000000_1.txt WA 161 ms 8052 KB
subtask1_100000000000_100000000000.txt WA 153 ms 8056 KB
subtask1_100000000000_2.txt WA 153 ms 8148 KB
subtask1_100000000000_3.txt AC 165 ms 8144 KB
subtask1_100000000000_50000000000.txt WA 161 ms 8184 KB
subtask1_100000000000_50000000001.txt AC 165 ms 8184 KB
subtask1_100000000000_99999999999.txt AC 161 ms 8180 KB
subtask1_16983563041_1.txt WA 157 ms 8052 KB
subtask1_1_1.txt WA 153 ms 8184 KB
subtask1_1_2.txt AC 151 ms 8056 KB
subtask1_1_31415926535.txt AC 153 ms 8184 KB
subtask1_239484768_194586924.txt AC 157 ms 8056 KB
subtask1_2_1.txt WA 151 ms 8056 KB
subtask1_2_2.txt WA 157 ms 8180 KB
subtask1_31415926535_1.txt AC 160 ms 8176 KB
subtask1_49234683534_2461734011.txt AC 162 ms 8148 KB
subtask1_4_1.txt WA 153 ms 8148 KB
subtask1_58640129658_232122496.txt WA 151 ms 8148 KB
subtask1_68719476735_35.txt WA 161 ms 8052 KB
subtask1_68719476735_36.txt WA 156 ms 8056 KB
subtask1_68719476735_37.txt WA 153 ms 8184 KB
subtask1_68719476736_1.txt WA 154 ms 8056 KB
subtask1_68719476736_2.txt WA 157 ms 8148 KB
subtask1_72850192441_16865701.txt WA 153 ms 8184 KB
subtask1_79285169301_27.txt WA 157 ms 8148 KB
subtask1_82914867733_1676425945.txt WA 154 ms 8056 KB
subtask1_8594813796_75700.txt WA 149 ms 8184 KB
subtask1_87654_12345.txt WA 154 ms 8184 KB
subtask1_87654_138.txt WA 153 ms 8148 KB
subtask1_87654_30.txt WA 153 ms 8052 KB
subtask1_87654_4294967308.txt AC 153 ms 8184 KB
subtask1_87654_45678.txt AC 153 ms 8148 KB
subtask1_97822032312_49157112.txt WA 155 ms 8180 KB
subtask1_98750604051_977728851.txt WA 147 ms 8180 KB
subtask1_99999515529_1.txt WA 157 ms 8180 KB
subtask1_99999515529_316226.txt WA 150 ms 8148 KB
subtask1_99999515529_316227.txt WA 151 ms 8184 KB
subtask1_99999515529_316228.txt WA 153 ms 8148 KB
subtask1_99999515529_49999757765.txt WA 162 ms 8184 KB
subtask1_99999515529_49999757766.txt AC 157 ms 8048 KB
subtask1_99999515530_2.txt WA 155 ms 8180 KB
subtask1_99999999977_1.txt AC 161 ms 8184 KB
subtask1_99999999977_2.txt AC 153 ms 8184 KB
subtask1_99999999977_49999999989.txt WA 161 ms 8144 KB
subtask1_99999999977_49999999990.txt AC 165 ms 8184 KB
subtask1_99999999999_1.txt AC 165 ms 8184 KB
subtask1_99999999999_100000000000.txt AC 165 ms 8184 KB