#P9420. Counting Special Subsequences and Twin Numbers
Counting Special Subsequences and Twin Numbers
Counting Special Subsequences and Twin Numbers
This problem consists of two subtasks. You are given a single‐character input which is either A
or B
:
Subtask A: Subsequence 2023
Little Blue writes on the board all the integers from 1 to 2023 consecutively, forming a long digit string
[ S = 1;2;3;4;5;6;7;8;9;10;11;12;13;\cdots;2022;2023 ]
A subsequence of S is obtained by deleting some digits (possibly none) without changing the order of the remaining digits. Your task is to count how many subsequences of S are exactly equal to 2023. (Note that the four digits in 2023 must come in order.)
Subtask B: Twin Numbers
A positive integer \(x\) is called a twin number if it can be written as
[ x = p^2 \times q^2 = (p,q)^2, \quad \text{with } p\text{ and }q \text{ being distinct primes.} ]
You are to calculate how many twin numbers lie in the interval ([2333,;23333333333333]).
Note: Your program should read a single character from input. If the input is A
, solve Subtask A; if it is B
, solve Subtask B.
inputFormat
The input consists of a single line containing a single character, either A
or B
.
outputFormat
Output a single integer: if the input is A
output the number of subsequences of S that equal 2023; if the input is B
output the number of twin numbers \(x = p^2 q^2\) in the interval \([2333,\;23333333333333]\).
sample
A
9168198