[SWEA] 덕환이의 카드 뽑기

문제 보러가기

제한사항

이외의 제한사항은 없다.

첫번째 생각

자료형 크기만 고려하여 나눠주면 쉽게 해결할 수 있다.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import java.util.Scanner;
public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int t=1;t<=T;t++)
        {
            int N = sc.nextInt();
            long K = sc.nextLong();
            long r = 1;
            for(int i=1; i<N+1; i++)
            {
                r = (long) (r+K) % i + 1;
            }
            System.out.println("#"+t+" "+r);
        }
    }
}