CF2180A - A. Carnival Wheel

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class App {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Set<Integer> set = new HashSet<>();
        int n = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < n; ++i) {
            int max = -1;
            int l = sc.nextInt();
            int a = sc.nextInt();
            int b = sc.nextInt();
            set.add(a);
            max = Math.max(a, max);
            while (true) {
                int next = (a + b) % l;
                if (set.add(next) == false) {
                    System.out.println(max);
                    break;
                }
                max = Math.max(next, max);
                a = next;
            }
            set.clear();
        }
        sc.close();
    }
}
posted @ 2026-01-22 15:03  kayaker  阅读(12)  评论(0)    收藏  举报