#P6210. 「SWTR-4」Easy Math Problems

    ID: 6631 远端评测题 500~1000ms 128MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>数学高精度莫比乌斯反演

「SWTR-4」Easy Math Problems

Background

The math teacher assigned Little A 22 Easy Math Problems.

Problem Description

Given n,c,f,l,rn,c,f,l,r, define the set S={x∈N+∣gcd⁡(x,n)≤c}S=\{x\in\mathbb{N_+}\mid\gcd(x,n)\leq c\} and the set Q={x∈S∣l≤x≤r}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\%): n≤103n\leq 10^3, r≤103r\leq 10^3, f≤103f\leq 10^3.

Subtask 2(35%)2(35\%): n≤105n\leq 10^5, r≤105r\leq 10^5, f≤105f\leq 10^5.

Subtask 3(35%)3(35\%): n≤106n\leq 10^6, r≤1012r\leq 10^{12}, f≤1012f\leq 10^{12}.

Subtask 4(15%)4(15\%): n≤107n\leq 10^7, r≤10105r\leq 10^{10^5}, f≤10105f\leq 10^{10^5}.

For 100%100\% of the testdata, 1≤c≤n≤1071\leq c\leq n\leq 10^7, 1≤l≤r≤101051\leq l\leq r\leq 10^{10^5}, 1≤f≤101051\leq f\leq 10^{10^5}.

[Tips]

Want to solve this problem with nlog⁡nn\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