시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 128 MB120219911017.742%

문제

세 개의 정수 a, b, d가 주어지면, 다음의 세 조건을 만족하는 자연수 순서쌍 (x, y)의 개수를 구하는 프로그램을 작성하시오.

  1. 1 ≤ x ≤ a
  2. 1 ≤ y ≤ b
  3. x와 y의 최대공약수는 d이다.

입력

여러 개의 문제가 하나의 입력파일 내에 주어진다. 첫째 줄에 문제의 개수 n이 주어진다. 각각의 문제는 세 개의 정수 a, b, d로 이루어져 있다. 둘째 줄부터 한 줄에 한 문제씩, 문제를 나타내는 세 정수 a, b, d가 주어진다.

출력

각 문제의 답을 한 줄에 하나씩 출력하도록 한다.

제한

  • 1 ≤ N ≤ 50,000
  • 1 ≤ a, b, d ≤ 50,000
  • d ≤ a
  • d ≤ b

예제 입력 1

2
4 5 2
6 4 3

예제 출력 1

3
2

힌트

첫 번째 문제의 경우, (2,2), (2,4), (4,2) 세 개의 순서쌍이 존재한다. 두 번째 문제의 경우 (3,3), (6,3) 두 개의 순서쌍이 존재한다.

W3sicHJvYmxlbV9pZCI6IjE3OTIiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWFjZjVcdWM1N2RcdWMyMTgiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YzEzOCBcdWFjMWNcdWM3NTggXHVjODE1XHVjMjE4IGEsIGIsIGRcdWFjMDAgXHVjOGZjXHVjNWI0XHVjOWMwXHViYTc0LCBcdWIyZTRcdWM3NGNcdWM3NTggXHVjMTM4IFx1Yzg3MFx1YWM3NFx1Yzc0NCBcdWI5Y2NcdWM4NzFcdWQ1NThcdWIyOTQgXHVjNzkwXHVjNWYwXHVjMjE4IFx1YzIxY1x1YzExY1x1YzMwZCAoeCwgeSlcdWM3NTggXHVhYzFjXHVjMjE4XHViOTdjIFx1YWQ2Y1x1ZDU1OFx1YjI5NCBcdWQ1MDRcdWI4NWNcdWFkZjhcdWI3YThcdWM3NDQgXHVjNzkxXHVjMTMxXHVkNTU4X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