結果

問題 No.3498 Modulo Equation
コンテスト
ユーザー えおあて
提出日時 2026-04-17 21:46:11
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 6,069 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,046 ms
コンパイル使用メモリ 84,848 KB
実行使用メモリ 40,012 KB
最終ジャッジ日時 2026-04-17 21:46:19
合計ジャッジ時間 7,621 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.Random;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static {
        Runtime.getRuntime().addShutdownHook(new Thread(out::flush));
    }
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = 1;
        while (x % a != b % x) {
            x++;
        }
        out.println(x);
    }

    static long count(int l, int r, int d, int u) {
        long ans = 0;
        for (int x = l; x <= r; x++) {
            if (x < d || x%2 == 1) continue;
            if (u < x) {
                ans += u-d+1;
                continue;
            }
            ans += x-d+1;
        }
        for (int y = d; y <= u; y++) {
            if (y < l || y%2 == 1) continue;
            if (r < y) {
                ans += r-l+1;
                continue;
            }
            ans += y-l;
        }
        return ans;
    }

    static void printList(Iterable<?> list) {
        boolean first = true;
        for (Object item : list) {
            if (!first) out.print(" ");
            out.print(item);
            first = false;
        }
        out.println();
    }

    static void printArray(int[] a) {
        for (int i = 0; i < a.length; i++) {
            if (i > 0) out.print(" ");
            out.print(a[i]);
        }
        out.println();
    }

    static void printArray(long[] a) {
        for (int i = 0; i < a.length; i++) {
            if (i > 0) out.print(" ");
            out.print(a[i]);
        }
        out.println();
    }

    static void shuffle(int[] a) {
        Random random = new Random();
        for (int i = a.length - 1; i > 0; i--) {
            int index = random.nextInt(i + 1);
            int temp = a[index];
            a[index] = a[i];
            a[i] = temp;
        }
    }

    static class BinarySearch {
        /* key以上の値がはじめてあらわれるインデックス (or a.length)*/
        public static int lowerBound(int[] a, int key) {
            int ok = a.length;
            int ng = -1;
            while (Math.abs(ok - ng) > 1) {
                int mid = (ok + ng) / 2;
                if (a[mid] >= key) ok = mid;
                else ng = mid;
            }
            return ok;
        }

        /* keyより大きい値がはじめてあらわれるインデックス (or a.length)*/
        public static int upperBound(int[] a, int key) {
            int ok = a.length;
            int ng = -1;
            while (Math.abs(ok - ng) > 1) {
                int mid = (ok + ng) / 2;
                if (a[mid] > key) ok = mid;
                else ng = mid;
            }
            return ok;
        }
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return buflen > 0;
            }
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            if (!hasNext()) throw new NoSuchElementException();
            int n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public double nextDouble() { return Double.parseDouble(next());}

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }
    }
}
0