Logo
(追記) (追記ここまで)

14316번 - Sherlock and Watson Gym Secrets (Small) 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB88392840.580%

문제

Watson and Sherlock are gym buddies.

Their gym trainer has given them three numbers, A, B, and N, and has asked Watson and Sherlock to pick two different positive integers i and j, where i and j are both less than or equal to N. Watson is expected to eat exactly iA sprouts every day, and Sherlock is expected to eat exactly jB sprouts every day.

Watson and Sherlock have noticed that if the total number of sprouts eaten by them on a given day is divisible by a certain integer K, then they get along well that day.

So, Watson and Sherlock need your help to determine how many such pairs of (i, j) exist, where i != j. As the number of pairs can be really high, please output it modulo 109+7 (1000000007).

입력

The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of one line with 4 integers A, B, N and K, as described above.

출력

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the required answer.

제한

  • 1 ≤ T ≤ 100.
  • 0 ≤ A ≤ 106.
  • 0 ≤ B ≤ 106.
  • 1 ≤ K ≤ 10000.
  • 1 ≤ N ≤ 1000.

예제 입력 1

3
1 1 5 3
1 2 4 5
1 1 2 2

예제 출력 1

Case #1: 8
Case #2: 3
Case #3: 0

힌트

In Case 1, the possible pairs are (1, 2), (1, 5), (2, 1), (2, 4), (4, 2), (4, 5), (5, 1), and (5, 4).

In Case 2, the possible pairs are (1, 2), (1, 3), and (4, 1).

In Case 3, No possible pairs are there, as i != j.

출처

Contest > Google > Google's Coding Competitions > Google APAC 2017 University Test > Round B APAC Test 2017 B1번

Contest > Google > Kick Start > Google Kick Start 2016 > Round B B1번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /