Submission #927757


Source Code Expand

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author liymsheep
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long a = 1, b = 1;
            for (int i = 0; i < n; ++i) {
                long u = in.nextInt(), v = in.nextInt();
                long g = BigInteger.valueOf(u).gcd(BigInteger.valueOf(v)).longValue();
                u /= g;
                v /= g;

                long ratio = Math.max((a + u - 1) / u, (b + v - 1) / v);
                a = u * ratio;
                b = v * ratio;
            }
            out.print(a + b);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new UnknownError();
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}

Submission Info

Submission Time
Task C - AtCoDeer and Election Report
User littlesheep
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 2128 Byte
Status AC
Exec Time 126 ms
Memory 9424 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 15
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt
Case Name Status Exec Time Memory
0_000.txt AC 102 ms 8788 KB
0_001.txt AC 99 ms 8528 KB
0_002.txt AC 98 ms 8528 KB
1_003.txt AC 98 ms 8528 KB
1_004.txt AC 126 ms 9296 KB
1_005.txt AC 102 ms 8656 KB
1_006.txt AC 120 ms 9040 KB
1_007.txt AC 106 ms 8784 KB
1_008.txt AC 101 ms 8656 KB
1_009.txt AC 99 ms 8532 KB
1_010.txt AC 100 ms 8656 KB
1_011.txt AC 100 ms 8528 KB
1_012.txt AC 100 ms 8656 KB
1_013.txt AC 126 ms 9424 KB
1_014.txt AC 119 ms 9420 KB