RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00476

Pictionary

Unrated 레이팅 미적용
난이도
1s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

1.5 \(s / 64\) \(MB / 140\) points

There is a planet, in a yet undiscovered part of the universe, with a country inhabited solely

by mathematicians. In this country, there are a total of \(N\) mathematicians, and the interesting

fact is that each mathematician lives in their own city. Is it also interesting that no two cities

are connected with a road, because mathematicians can communicate online or by

reviewing academic papers. Naturally, the cities are labeled with numbers from 1 to \(N\) .

Life was perfect until one mathematician decided to write an academic paper on their

smartphone. The smartphone au\(to-co\)rrected the word “se\(lf-ev\)ident” to “Pictionary” and the

paper was published as such. Soon after, the entire country discovered pictionary and

wanted to meet up and play, so construction work on roads between cities began shortly.

The road construction will last a total of \(M\) days, according to the following schedule: on the

first day, construction is done on roads between all pairs of cities that have \(M\) as their

greatest common divisor. On the second day, construction is done on roads between all

pairs of cities that have \(M-1\) as their greatest common divisor, and so on until the \(M\) ^{th} day

when construction is done on roads between all pairs of cities that are \(co-pr\)ime. More

formally, on the \(i\) ^{th} day, construction is done on roads between cities \(a\) and \(b\) if gcd(a, b) = M

  • \(i + 1\) .

Since the mathematicians are busy with construction work, they’ve asked you to help them

determine the minimal number of days before a given pair of mathematicians can play

pictionary together.

제약

In test cases worth 40% of total points, it will hold \(N\) ≤ 1000, \(Q\) ≤ 100 000.

1.5 \(s / 64\) \(MB / 140\) points

입력 형식

The first line of input contains three positive integers N, M and \(Q\) (1 ≤ \(N\) , \(Q \le 100\,000\), 1 ≤ \(M\)

\(N\) ), the number of cities, the number of days it takes to build the roads, and the number of

queries.

Each of the following \(Q\) lines contains two distinct positive integers \(A\) and \(B\) (1 ≤ \(A\) , \(B\)\(N\) )

that denote the cities of the mathematicians who want to find out the minimal number of days

before they can play pictionary together.

출력 형식

The \(i\) ^{th} line must contain the minimal number of days before the mathematicians from the \(i\) ^{th}

query can play pictionary together.

예제 1
입력
8 3 3
2 5
3 6
4 8
출력
3
1
2
예제 2
입력
25 6 1
20 9
출력
4
예제 3
입력
9999 2222 2
1025 2405
3154 8949
출력
1980
2160
문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2017/2018 Contest 5

평가 및 의견

Pictionary

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Pictionary

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8