0% found this document useful (0 votes)
17 views22 pages

Tama 2023

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views22 pages

Tama 2023

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

National Olympiad in Informatics

TAMa
National Olympiad in Informatics

TAMa

Important! Read the following:


• Unlike in other NOI.PH contests, your answer to each subtask is a single
number, not code.
◦ For each subtask, substitute in that subtask’s value of n (or m, or
whatever parameters) and solve the problem, given that value.
◦ Type only the final answer into the input field for that subtask.
◦ When making a submission, you may choose to answer only one subtask
at a time (leaving the other fields blank). Your total score counts a
subtask as solved if any previous submissions have solved that subtask.
• Do not put commas or spaces in numerical output. For example, if the
problem is to compute 1111 × 1111, submit 1234321 not 1,234,321.
• It is highly recommended to aim for 100 points in every problem before
going for 150 or 200 points in most problems.
• Each problem has been designed according to a “one-minute rule”.
◦ We guarantee that for all subtasks of all problems, a sufficiently efficient
algorithm exists that allows the answer to be obtained on a modestly-
powered computer in less than one minute.
◦ Of course, for particularly tricky problems, it may take you much longer
than that to come up with the solution!
◦ Although this rule will not be strictly enforced, we greatly encourage
you to try and follow it! You’ll learn new and interesting techniques if
you choose to take this path, and we believe it is the most fun!
• You are encouraged to use the internet as a resource while solving these
problems. We hope that in your research for this contest, you come across
and learn many new topics in mathematics!
• The perfect score for this contest is 2023 points.
• Finding the problems too hard? Please join our upcoming Abakoda 2023
Beginner Programming Contests which start on November 11th! Stay
tuned in our Discord for more details.
• Good luck and enjoy the contest!

1
National Olympiad in Informatics

TAMa

Contents
A: Squares of Even Lucas Numbers 3

B: GCD of Fibonacci Subsets 4

C: Fruity Fractions 5

D: Sweet Tile O’ Mine 6

E: The Glass Maze 8

F: Hit the Griddy 10

G: The Amazons’ Primes 12

H: Pillage Twilight Heroes 14

I: The Idea is to Sacrifice THE ROOOOOOOK 16

J: Immortal Plans 18

sTANDARD eTHICAL aMAT 21

Table of Contents 2
National Olympiad in Informatics

TAMa

Problem A
Squares of Even Lucas Numbers
The Lucas sequence L0 , L1 , L2 , L3 , L4 , L5 , . . . is defined as follows. We let L0 = 2
and L1 = 1, then for n ≥ 2, we let

Ln = Ln−1 + Ln−2 .

In other words, much like the Fibonacci sequence, each next term in the Lucas
sequence is equal to the sum of the previous two terms. Its first few terms are:

2, 1, 3, 4, 7, 11, 18, 29, 47, 76, . . .

Given n, let s be the sum of the squares of all even-valued terms of the Lucas
sequence with index < n. What is the remainder when s is divided by m? (Also
known as “s mod m”)
For example:
• If n = 9, the sum is s = 22 + 42 + 182 = 344. Then, if m = 5, the answer is
(344 mod 5) = 4.
• If n = 100 and m = 2023, then the answer is 272.

Subtasks
To be awarded the points for each subtask, answer the problem, given that sub-
task’s values of n and m.

Subtask Points Constraints


1 50 n = 30 and m = 1000
2 50 n = 106 + 2023 and m = 998244353
3 50 n = 1015 + 2023 and m = 88 + 2023
4 25 n = 1015 + 3000 and m = 1018 + 3000
5 25 n = 1015 + 2999 and m = 1018 + 2999

A: Squares of Even Lucas ... 3


National Olympiad in Informatics

TAMa

Problem B
GCD of Fibonacci Subsets
The Fibonacci sequence F0 , F1 , F2 , F3 , F4 , . . . is defined as follows. We let F0 = 0
and F1 = 1, then for n ≥ 2, we let

Fn = Fn−1 + Fn−2 .

In other words, much like the Lucas sequence, each next term in the Fibonacci
sequence is equal to the sum of the previous two terms. An integer is called a
Fibonacci number if it appears in this sequence. The first few positive Fibonacci
numbers are:

1, 2, 3, 5, 8, 13, 21, . . .

Consider the set S which consists of the first n positive Fibonacci numbers. If A is
a non-empty subset of S, then we define gcd(A) (read as the greatest common
divisor of A) to be the largest integer d such that every element of A is divisible
by d. For example, if n = 7, then the first seven positive Fibonacci numbers are
{1, 2, 3, 5, 8, 13, 21}, of which {2, 8} is a non-empty subset, and gcd({2, 8}) = 2.
Given n, what is the sum of gcd(A) across all non-empty subsets A of S? The
answer can get quite huge, so give the remainder when this result is divided by
998244353.
For example:
• if n = 7, the sum is 176;
• if n = 30, the sum is 1077269960, so the answer is

(1077269960 mod 998244353) = 79025607.

Subtasks
To be awarded the points for each subtask, answer the problem, given that sub-
task’s value of n.

Subtask Points Constraints


1 50 n = 12
2 50 n = 54
3 25 n = 104
4 25 n = 107
5 50 n = 1111

B: GCD of Fibonacci Subsets 4


National Olympiad in Informatics

TAMa

Problem C
Fruity Fractions
For some reason beyond our mortal understanding, the following math problem
has gone viral and is now trending on the social media platform ξ dot com:
Only 99% of geniuses can solve this problem
2 2 3 1
+ = +
+2 2 − +3

Can you find integer values for , , ?

This turns out to not be so hard. For example, ( , , ) = ( , , )


is one such solution, and you can find infinitely many more solutions.
Note that the denominators are nonzero in any valid solution.
For the actual task: Given a positive integer n, count the number of integer
solutions ( , , ) to the above problem, such that max(| |, | |, | |) ≤ n
(note the use of absolute value functions). This number can get quite huge, so
give the remainder when this result is divided by 998244353.
For example,
• if n = 5, the answer is 30;
• if n = 105 , the answer is 679988514.
Do not submit your answer using emojis for digits.

Subtasks
To be awarded the points for each subtask, answer the problem, given that sub-
task’s value of n.

Subtask Points Constraints


1 50 n = 35
2 50 n = 55
3 50 n = 510
4 50 n = 1510

C: Fruity Fractions 5
National Olympiad in Informatics

TAMa

Problem D
Sweet Tile O’ Mine
Kelly Kawno is collaborating with famous YouTuber Mr Feast to expand into the
chocolatiering business! They plan to release a line of chocolates called “Beast
Bars,” so named because you will feel like a beast after eating one!
The Beast Bar shall be a rectangle consisting of r rows and c columns, split into
r × c unit squares. Each bar is assembled by connecting together various chocolate
pieces called “tiles” like a gigantic jigsaw puzzle. Here are the various kinds of tiles
that Mr Feast can use!

Note that:
• Rotations of tiles are considered to be distinct from one another
• There are two different tiles whose shape is a 2 × 2 square—one made of milk
chocolate, and one made with malt sugar extract.
For example, here are five different valid ways to construct a Beast Bar when r = 3
and c = 4. Note that there must be no overlap between pieces, and no “extra”
squares outside the rectangle.

D: Sweet Tile O’ Mine 6


National Olympiad in Informatics

TAMa

How many different ways are there to construct an r × c Beast Bar? Two ways
are considered different if there exists a square that belongs to a different kind of
tile between the two ways. This number can get quite huge, so give the remainder
when this result is divided by 998244353.
For example:
• if r = 2 and c = 2, the total count is 13. There are 13 ways to construct a
2 × 2 Beast Bar, as illustrated below:

• if r = 3 and c = 4, the answer is 4773;


• if r = 7 and c = 7, the answer is 297815281.

Subtasks
To be awarded the points for each subtask, answer the problem, given that sub-
task’s values of r and c.

Subtask Points Constraints


1 50 r = 2 and c = 8
2 50 r = 3 and c = 106
3 25 r = 3 and c = 1018
4 25 r = 7 and c = 106
5 25 r = 7 and c = 1018
6 25 r = 13 and c = 1018

D: Sweet Tile O’ Mine 7


National Olympiad in Informatics

TAMa

Problem E
The Glass Maze
Pusit Bulaga, the Philippines’ most popular noontime variety show, has hired you
as a consultant to help analyze the game in their brand new segment, the glass
maze. The glass maze can be represented as a square grid with n rows and n
columns. Let (i, j) represent the cell in the ith row from the top and jth column
from the left, where 1 ≤ i ≤ n and 1 ≤ j ≤ n.
A panel of glass is placed in each cell. The glass panel in cell (i, j) can hold a
weight of at most bi,j milligrams; any more than that, and the panel breaks.
For example, if n = 4, then the maze has 4 rows and 4 columns, and the glass
maze could be represented by the grid with the following values:
2000023 55500000 55500000 75000000
60000000 86236000 42000000 87000000
75000000 90000000 50000000 5000000
999999999 40000000 60000000 87000000
In this grid, b1,1 = 2000023, b1,2 = 55500000, and so on.
A contestant, holding all their treasure, begins the challenge by being placed on
some cell (is , js ). Their objective is to safely travel to cell (it , jt ) in order to escape.
In one move, a contestant can jump to any of the cells directly north, south, east,
or west from their current cell (provided such a cell exists).
If at any time a contestant is on a glass panel (including the ones at (is , js ) and
(it , jt )) and their weight exceeds the weight limit of that glass panel, then that
panel breaks and the contestant plummets to their doom, losing all their treasure.
For a given grid, let W (is , js , it , jt ) be defined as the maximum weight w (in mil-
ligrams) such that it is possible for a person with weight w to successfully travel
from (is , js ) to (it , jt ) via some path. For example, for the grid above, you can
check that W (1, 4, 4, 3) = 50000000, as illustrated below.
2000023 55500000 55500000 75000000
60000000 86236000 42000000 87000000
75000000 90000000 50000000 5000000
999999999 40000000 60000000 87000000

E: The Glass Maze 8


National Olympiad in Informatics

TAMa

But that grid is just an example. The actual values of bi,j for the real game are
generated by the game designers via the following formula:

bi,j = 16696612023×i×j mod 998244353,

where again, i and j both range from 1 to n. For example, if n = 2, then the
panels’ weight limits look like this:
287271328 149369469
149369469 817235580
Given n, evaluate the sum of W (is , js , it , jt ) across all tuples (is , js , it , jt ) such that
1 ≤ is , it , js , jt ≤ n and (is , js ) 6= (it , jt ); there are n4 −n2 such tuples. This number
can get quite huge, so give the remainder when this result is divided by 998244353.
For example:
• For n = 2, the sum is 1792433628, so the answer is

(1792433628 mod 998244353) = 794189275.

• For n = 5, the sum is 188167059380, so the answer is

(188167059380 mod 998244353) = 497121016.

Subtasks
To be awarded the points for each subtask, answer the problem, given that sub-
task’s value of n.

Subtask Points Constraints


1 50 n=4
2 50 n = 12
3 25 n = 143
4 25 n = 3141
5 50
3
n = 33

E: The Glass Maze 9


National Olympiad in Informatics

TAMa

Problem F
Hit the Griddy
Suppose we have been tasked with creating a compilation grid of memes with r
rows and c columns. In each of the rc cells, you can either put a cool meme or a
cringe meme. If coolness and cringeness are the only things that matter in life,
then that means there are 2rc possible compilation grids.
As we all know, two cringe memes cancel out and become cool again. Thus, a
compilation grid G is called based if it satisfies both of these conditions:
• There are an even number of cringe memes in every row.
• There are an even number of cringe memes in every column.
Given an arbitrary compilation grid G, let B(G) be the minimum number of memes
that need to be transformed (either from cringe to cool, or cool to cringe) such
that G becomes based. Note that if G is already based, then B(G) = 0.
For example, let indicate a cool meme, and let indicate a cringe meme.
If r = 3 and c = 4, then one possible compilation grid G is

This G is not already based, but can be made based by changing only one meme
(turn the top-rightmost meme from cool to cringe); thus, B(G) = 1.
Given r and c, output the sum of (B(G))3 across all 2rc possible compilation grids
G that have r rows and c columns. This number can get quite huge, so give the
remainder when this result is divided by 998244353.
For example,
• if r = 3 and c = 5, then the answer is 858624;
• if r = 6 and c = 9, then the answer is 419465649.

F: Hit the Griddy 10


National Olympiad in Informatics

TAMa

Subtasks
To be awarded the points for each subtask, answer the problem, given that sub-
task’s values of r and c.

Subtask Points Constraints


1 50 r = 5, c = 5
2 50 r = 64, c = 100
3 25 r = 4000, c = 5000
4 25 r = 6400000, c = 6400000
5 50 r = 64000000, c = 1016

F: Hit the Griddy 11


National Olympiad in Informatics

TAMa

Problem G
The Amazons’ Primes
Maxi and Mini are twin warrior sisters who also recreationally indulge in math-
ematics. Specifically, both of them love prime numbers, but in very different
ways—Maxi likes large primes, whereas Mini likes little primes.
Suppose both sisters start with a shared positive integer sequence [a1 , a2 , . . . , an ]
whose elements are all greater than 1.
Maxi generates the Maxi-sequence [M1 , M2 , . . . , Mn ] by replacing each element
of a with its largest prime factor, i.e.,

Mi = largest prime that divides ai

for each i from 1 to n. Similarly, Mini generates the Mini-sequence [m1 , m2 , . . . , mn ]


by replacing each element of a with its smallest prime factor, i.e.,

mi = smallest prime that divides ai

for each i from 1 to n.


Given integers n and b, we say a sequence of n integers [a1 , a2 , . . . , an ] is Amazing
if it satisfies all of the following conditions:
• 1 < ai < b for all i from 1 to n;
• Its corresponding Maxi-sequence M is strictly increasing;
• Its corresponding Mini-sequence m is also strictly increasing.
How many Amazing sequences are there? This number can get quite huge, so give
the remainder when this result is divided by 998244353.
For example:
• if n = 4 and b = 400, then [256, 45, 385, 169] would be one Amazing sequence,
and there are 60834149 such Amazing sequences overall;
• if n = 3 and b = 18, then there are 169 Amazing sequences;
• If n = 69 and b = 420, then there are 468140835430514395 Amazing se-
quences, so the answer is

(468140835430514395 mod 998244353) = 968682385.

G: The Amazons’ Primes 12


National Olympiad in Informatics

TAMa

Subtasks
To be awarded the points for each subtask, answer the problem, given that sub-
task’s values of n and b.

Subtask Points Constraints


1 50 n = 10, b = 48
2 50 n = 100, b = 4000
3 50 n = 2400, b = 300000
4 50 n = 80000, b = 12000000

G: The Amazons’ Primes 13


National Olympiad in Informatics

TAMa

Problem H
Pillage Twilight Heroes
Pillage Twilight Heroes is an all-new multiplayer game, and it’s completely free!
Throughout the game, you have to collect weapons to defeat increasingly strong
enemies in round-based combat. Every weapon has an associated power rating (a
positive integer) that determines how much damage it can deal every round.
Starting off with no weapons, a party of n players plans to use the promo code
“PILLAGE999” to get w weapons, each with a power rating chosen independently
and uniformly at random from the integers from 1 to k. Different weapons may
get the same power rating. From here, each player must select a weapon, but no
two players may pick the same one.
The players in the party are smart and will pick the n weapons with the highest
power ratings (if there is a tie for the nth strongest weapon, the players break the
tie arbitrarily by picking their favorite of those weapons).
For example, suppose n = 2, w = 6, and k = 3.
• After inputting the promo code, we generate w = 6 weapons with random
power ratings from 1 to k = 3; one possible outcome would be weapons with
power ratings [2, 3, 1, 2, 2, 1].
• The party of n = 2 picks the two strongest weapons—which in the case of
this outcome, would be the weapon with power rating 3, and then any of
the weapons with power rating 2. The sum of the party’s weapons’ power
ratings would be 3 + 2 = 5.
• If we were to repeat this process many many times, we find that on average,
we should expect the sum of the party’s weapons’ power ratings to be
4040/729 ≈ 5.5418.
The developers of Pillage Twilight Heroes don’t want the game to be too easy
or too hard, so they ask you a simple question. You are given n, w, and k. On
average, what do we expect to be the value of the sum of the party’s weapons’
power ratings, assuming that the weapons were generated and then selected via
the described process? It can be shown that this number is rational; output this
number “mod 998244353”. (What does this mean? See the Notes below for an
explanation of what this means.)

H: Pillage Twilight Heroes 14


National Olympiad in Informatics

TAMa

Here are some examples:


• If n = 2, w = 3 and k = 6, the average is 203/24. It turns out that

(203/24 mod 998244353) = 207967582,

so that’s the answer.


• If n = 2, w = 6 and k = 3, the average is 4040/729. It turns out that

(4040/729 mod 998244353) = 191706740,

so that’s the answer.

Subtasks
To be awarded the points for each subtask, answer the problem, given that sub-
task’s values of n, w and k.

Subtask Points Constraints


1 50 n = 5, w = 50, k = 5
2 50 n = 200, w = 500, k = 300
3 25 n = 600, w = 108 , k = 500
4 25 n = 9000, w = 1016 , k = 9000
5 50 n = 2500000, w = 1016 , k = 500000

Notes
What does a rational number modulo a prime mean? Let r be a rational and p be
a prime. We define r modulo p to be the unique integer r0 such that 0 ≤ r0 < p
and the rational number r − r0 is “divisible by p”. (Sometimes, this doesn’t exist,
but it can be shown that it does for the answers to this problem.)
What does it mean for a rational number to be divisible by a prime? We say that
a rational number is divisible by p if and only if it can be expressed as a/b for
integers a and b, where a is divisible by p, but b is not.
For example, 35/14 and 150/77 are divisible by 5, but 7/8 and 3/10 are not. Also,
(16/3 mod 5) = 2 because 16/3 − 2 = 10/3, and 10/3 is divisible by 5.

H: Pillage Twilight Heroes 15


National Olympiad in Informatics

TAMa

Problem I
The Idea is to Sacrifice THE ROOOOOOOK
Consider a variation of chess which takes place on a grid with r rows and c columns
(and thus rc cells). There are no “colors”, and the only piece is the rook. A rook
can move any number of steps horizontally or vertically without “jumping over”
other pieces, and may capture any piece in its path. If a rook can capture some
piece, we say that this rook threatens that piece.
For example, in the following board where r = 5 and c = 8, the rook at d3
(encircled green) threatens the rooks at d5, e3, a3, and d1 (boxed red), but does
not threaten the rooks at f2 or h3 (boxed blue).

5
Z0ZrZ0Z0
4
0Z0Z0Z0Z
3
s0Zrs0Zr
2
0Z0Z0s0Z
1
Z0ZrZ0Z0
a b c d e f g h

We say a chessboard consisting of rooks is unstable if there exists a non-negative


integer d such that:
• For every rook, there are exactly d other rooks in the same row as it that
threaten it.
• For every rook, there are exactly d other rooks in the same column as it that
threaten it.
For example, the following chessboard with r = 5 rows and c = 8 columns is
unstable (taking d = 1):

Z0Z0Z0Z0
0s0Z0ZrZ
Z0Z0Z0Z0
0Z0s0ZrZ
ZrZrZ0Z0
There are many such chessboards; in fact, there are exactly 168461 unstable chess-
boards with r = 5 rows and c = 8 columns.

I: ... THE ROOOOOOOK 16


National Olympiad in Informatics

TAMa

Given n, what is the number of unstable chessboards with exactly n cells? This
number can get quite huge, so give the remainder when this result is divided by
998244353.
For example,
• if n = 66, then the number of unstable chessboards is 76683692;
• if n = 100, then the number of unstable chessboards is 3239590777554, so
the answer is

(3239590777554 mod 998244353) = 287852069.

Two chessboards are considered the same iff they have the same number of rows,
the same number of columns, and the same locations of rooks. (Each cell can
only be empty or contain one rook.) Also, note that rotations and reflections are
considered distinct.

Subtasks
To be awarded the points for each subtask, answer the problem, given that sub-
task’s value of n.

Subtask Points Constraints


1 50 n = 77
2 50 n = 3000
3 25 n = 303
4 25 n = 425
5 25 n = 915
6 25 n = 1015

I: ... THE ROOOOOOOK 17


National Olympiad in Informatics

TAMa

Problem J
Immortal Plans
It is the beginning of January 1, 4000, and the immortal witch Bernkastel
desperately wants to cure her boredom. She has watched every TV show created
by humanity—listened to every song, played every game, read every book, and
committed every crime (she doesn’t recommend this last one). In the end, she
always becomes bored with whatever new thing she tries to get into.
You point out that maybe her boredom stems from the fact that she binges every-
thing, which leads to her easily getting sick of them. Perhaps if she spaced out her
activities better, then she would still be able to find excitement in them when she
comes back to repeat them. Intrigued, she asks you to develop a plan for her.
• Every day, you must choose an activity for her to do. Suppose there are c
different activities to choose from for each day.
• A “plan” consists of specifying which activity she should do, every single
day, for the next n years.
◦ This plan will last for the rest of her immortal life—after the nth year,
she cycles back to the first day of the first year of the plan... and so on.
◦ For the easier version of this problem, we consider a universe
where leap years do not exist. For full points, you must handle leap
years. See the notes for a full explanation on the structure of a year.
• For a plan to be properly-spaced, it must satisfy the following constraints:
◦ For any two consecutive days in Bernkastel’s infinite life, it is never the
case that the activities performed on each day are the same.
◦ For any two consecutive months in Bernkastel’s infinite life, it is never
the case that the activities performed on the first day of each month
are the same.
For example, suppose n = 400 and c = 3, and leap years exist. Let’s label the
three activities 1, 2, and 3. Here are the beginnings of one possible plan:
• For January 1 to 31, 4000, we may choose activities in the pattern
1, 2, 3, 2, 1, 2, 3, 2, . . . , 1, 2, 3.
• For February 1, 4000, activity 3 was chosen on the previous day (January
31) whereas activity 1 was chosen on the first day of the previous month
(January 1); therefore, we are forced to pick activity 2 for this day.
◦ Note that 4000 would be a leap year in a universe where those exist.
◦ For February 1 to 29, 4000, we may choose activities in the pattern:
2, 3, 2, 3, 2, 3, . . . , 2, 3, 2.

J: Immortal Plans 18
National Olympiad in Informatics

TAMa

• Repeat this, choosing the activities of every day of every month, until De-
cember of 4399.
Because n = 400, the cycle repeats after 400 years, and we have no more
choices to make: the month of January 4400 will again follow the pattern
1, 2, 3, 2, 1, . . . , 1, 2, 3; then February 4400 will again follow the pattern 2, 3, . . . , 3, 2;
...and so on, for the rest of time. Note that because of this, it is important to
guarantee that neither December 1, 4399 nor December 31, 4399 have activity 1
selected, because January 1 (in the year 4400) comes after.
Let P (n, c) count the number of properly-spaced plans if there are c activities to
choose from for each day for the next n years.
For example, again consider n = 400 and c = 3.
• In the universe where leap years don’t exist,

P (400, 3) mod 9982443520000001 = 6294703839080434.

• In the universe where leap years do exist,

P (400, 3) mod 9982443520000001 = 1601108114453425.

These values are gigantic, which is why we only gave them modulo a large prime.
Given n and C, find the sum of P (n, c) across all integers c from 1 to C. Only
give the remainder when this sum is divided by 9982443520000001. We remind
you that here, the first year of the plan happens in the year 4000.
For example, suppose n = 400 and C = 4. Then the required answer is

(P (400, 1) + P (400, 2) + P (400, 3) + P (400, 4)) mod 9982443520000001;

in a universe where leap years do not exist, the answer is 7308545946151460, and
in a universe where leap years do exist, the answer is 8403801211504682.

J: Immortal Plans 19
National Olympiad in Informatics

TAMa

Subtasks
To be awarded the points for each subtask, answer the problem, given that sub-
task’s values of n and C, and whether or not leap years exist.

Subtask Points Constraints


1 50 Leap years do not exist, n = 1 and C = 3
2 25 Leap years do not exist, n = 4 and C = 10
3 25 Leap years exist, n = 400 and C = 10
4 25 Leap years exist, n = 400 and C = 2023
5 25 Leap years exist, n = 400 and C = 1018
6 25 Leap years exist, n = 2000 and C = 1018
7 25 Leap years exist, n = 10000 and C = 1018

Notes
A normal calendar year has 365 days split into 12 months. The 12 months are,
in order: January, February, March, April, May, June, July, August, September,
October, November, December. Each month consists of some number of days.
• These months have 31 days: January, March, May, July, August, October,
December.
• These months have 30 days: April, June, September, November.
• These months have 28 days: February.
A leap year has 366 days, with the only change from a normal calendar year
being that February has 29 days instead. For subtasks 1 and 2, there are no leap
years. For subtasks 3 through 7, they are determined by the following rules:
• By default, we assume that a year is not a leap year.
• But, if a year is divisible by 4, it is a leap year.
• As an exception to this rule, if a year is divisible by 100, it is not a leap year.
• As an exception to the exception, if a year is divisible by 400, it is a leap
year.
For example, the following would be leap years: 4000, 4028, 123456, and 777200;
and the following would not be leap years: 4321, 5000, 20232023, and 99999900.
For subtasks 3 through 7, the given n is divisible by 400, in order for the problem
to make sense.

J: Immortal Plans 20
National Olympiad in Informatics

TAMa

Bonus Problem
sTANDARD eTHICAL aMAT
Nwv whk, n ethical wn ’vy snwj’w pn-ratohrh. Rnwn’o ln-awzho lh ’dh!
Dfa standard uhllhw vymyrht ht suv hg dkh ehrydyma ywdasatr l nwv m yr n
uhllhw vymyrht hg l nwv m dfnd yr standat dfnw nwo hdfat uhllhw vymyrht hg l
nwv m. Eht azalech:
• dfa suv hg 8577 nwv 8577 yr 8577;
• dfa suv hg 155 nwv 1071 yr 75;
• dfa suv hg 7171 nwv 71500 yr 5;
• dfa suv hg 928986 nwv 892396 yr 8;
• dfa suv hg 76 nwv 58 yr 76.
Wand ’wh? Wnslnond!
Gjw gnud: Yw Znenwara yd yr unccav “rnyvny phjonpjrjj”; rn Phtanw wnln’o
“ufhavnashwsonprj”. Rn pnrnlnnws encnv, entnws kncn r’onws Dnsnchs DhD.
’Ens dywnwhws lh wnlnw ry Shhsca, “eywnpnlncnpyws pntnwyknws vymyrht”
’ojws rnrniyfyw w’on. Entnws eycyd cnws ’vy in? RDAL ucnrrar yw EF dawv
dh ia dnjsfd yw AWScyrf, ht nd iard DNScyrf (ht ’ojws tasyhwnc cnwsjnsa) kydf
daufwyunc khtvr jwdtnwrcndav. Yd tancco lnpar ohj gaac cypa n lncnwrnws gyrf!
Nwokno, tysfd, inup dh ethical. Whk, ka rno dfnd n dtyecad hg ehrydyma yw-
dasatr (n, o, i) yr pndnpndnpn yg yd rndyrgyar ncc hg dfa ghcchkyws:
• dfa suv hg n nwv o yr i;
• dfa vauylnc taetarawdndyhw hg n hwco jrar dfa vysydr 8, 1 nwv 6, nwv anuf
hg dfhra neeantr nd canrd hwua;
• dfa vauylnc taetarawdndyhw hg o hwco jrar dfa vysydr 3, 5 nwv 7, nwv anuf
hg dfhra neeantr nd canrd hwua;
• dfa vauylnc taetarawdndyhw hg i hwco jrar dfa vysydr 4, 9 nwv 2, nwv anuf
hg dfhra neeantr nd canrd hwua.
Ght hjt ejtehrar, dfa vauylnc taetarawdndyhw hg n ehrydyma ywdasat yr jwyqja
nwv vharw’d fnma n canvyws bath.
Nlhws ncc dtyecar (n, o, i) dfnd nta pndnpndnpn, kfnd yr dfa lywyljl ehrryica
mncja hg n · o · i?
Idk ihwjr cnws ’dhws ethical wn ’dh! Zjrd ght gjw :E Dfyr ethical yr hwco khtdf
25 ehywdr. Ijd rdycc, pjws ln-rhcma lh r’on, ether dh ohj. Sjvcnp! Nwv yg ohj’ta
nica dh tanv dfyr, ecanra rno yw dfa WHY ratmat dfnd dfyr ethical yr etaddo
rdnwvntv (nwv adfyunc tyw r’oaleta)!

sTANDARD eTHICAL aMAT 21

You might also like