#P6210. 「SWTR-4」Easy Math Problems

「SWTR-4」Easy Math Problems

Description

Given n,c,f,l,rn,c,f,l,r, define the set S={xN+gcd(x,n)c}S=\{x\in\mathbb{N_+}\mid\gcd(x,n)\leq c\} and the set Q={xSlxr}Q=\{x\in S\mid l\leq x\leq r\}.

  • Set SS contains all positive integers whose gcd\gcd with nn is at most cc, and set QQ contains the elements in SS that are not less than ll and not greater than rr.

Question 1: Find the ff-th smallest number in set SS.

Question 2: Find the number of elements in set QQ.

Since the numbers are very large, Little A wants you to help compute the answers.

Input Format

A single line with five integers n,c,f,l,rn,c,f,l,r — with meanings as described in the statement.

Output Format

Output two lines of integers — the first line is the answer to Question 1, and the second line is the answer to Question 2.

12 3 8 10 17

11
6
72 5 66 13 89

94
54
360360 123 20200202 123456789 987654321

21751721
802555475

Hint

[Sample 11 Explanation]

$S=\{1,2,3,5,7,9,10,11,13,14,15,17,\dots\},Q=\{10,11,13,14,15,17\}$. It can be seen that the 88-th smallest number in SS is 1111, and the number of elements in QQ is 66.

[Constraints and Notes]

This problem uses bundled tests.

Subtask 1(15%)1(15\%): n103n\leq 10^3, r103r\leq 10^3, f103f\leq 10^3.

Subtask 2(35%)2(35\%): n105n\leq 10^5, r105r\leq 10^5, f105f\leq 10^5.

Subtask 3(35%)3(35\%): n106n\leq 10^6, r1012r\leq 10^{12}, f1012f\leq 10^{12}.

Subtask 4(15%)4(15\%): n107n\leq 10^7, r10105r\leq 10^{10^5}, f10105f\leq 10^{10^5}.

For 100%100\% of the testdata, 1cn1071\leq c\leq n\leq 10^7, 1lr101051\leq l\leq r\leq 10^{10^5}, 1f101051\leq f\leq 10^{10^5}.

[Tips]

Want to solve this problem with nlognn\log n?

[Time Limit]

For the first 33 subtasks, the time limit is 1s1\rm{s}, and for the remaining subtask it is 500ms500\rm{ms}.

[Source]

Sweet Round 04  \ \ B

idea & std: Alex_Wei, verification: xtx1092515503 & FrenkiedeJong21 & chenxia25

Translated by ChatGPT 5