Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.util.StringTokenizer;
- public class Range {
- static long proveri(long N, long A, long B) {
- long left = A, right = B;
- while(left <= right) {
- long middle = (left + right) / 2;
- long tmp = middle;
- long sum = 0;
- while(tmp > 0) {
- sum += tmp % 10;
- tmp /= 10;
- }
- long resultEquation = middle * middle + 200 * middle + sum;
- if(resultEquation == N) {
- return middle;
- }
- if(resultEquation < N) {
- left = middle + 1;
- }
- else {
- right = middle - 1;
- }
- }
- return -1;
- }
- public static void main(String[] args) throws Exception {
- long i,j,k;
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- long N = Long.parseLong(br.readLine());
- StringTokenizer st = new StringTokenizer(br.readLine());
- long A = Long.parseLong(st.nextToken());
- long B = Long.parseLong(st.nextToken());
- long res = proveri(N, A, B);
- System.out.println(res);
- br.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement