CF117B.Very Interesting Game

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string _s_1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at _s_1 and writes a string _s_2, consisting of exactly nine digits and representing a number that does not exceed b. Here a and b are some given constants, _s_1 and _s_2 are chosen by the players. The strings are allowed to contain leading zeroes.

If a number obtained by the concatenation (joining together) of strings _s_1 and _s_2 is divisible by mod, then the second player wins. Otherwise the first player wins. You are given numbers a, b, mod. Your task is to determine who wins if both players play in the optimal manner. If the first player wins, you are also required to find the lexicographically minimum winning move.

在某个非常古老的国家,曾流行这样一种游戏:两人参与游戏。游戏开始时,先手玩家写下字符串 s1s_1,该字符串恰好由九位数字组成,且其所表示的数不超过 aa;随后,后手玩家观察 s1s_1,写下字符串 s2s_2,该字符串也恰好由九位数字组成,且其所表示的数不超过 bb。其中 aa 和 bb 是给定的常数,s1s_1 和 s2s_2 由双方玩家各自选择。字符串允许包含前导零。

若将字符串 s1s_1 和 s2s_2 拼接(即连接在一起)所得的数字能被 modmod 整除,则后手玩家获胜;否则先手玩家获胜。现给定整数 aa、bb、modmod,你的任务是判断:当双方均以最优策略进行游戏时,谁将获胜。若先手玩家获胜,你还需找出字典序最小的获胜第一步(即满足条件的字典序最小的 s1s_1)。

输入格式

The first line contains three integers a, b, mod (0 ≤ a, b ≤ 109, 1 ≤ mod ≤ 107).

第一行包含三个整数 aa、bb、mod\text{mod}(0 ≤ a, b ≤ 1090 \leq a,\,b \leq 10^9,1 ≤ mod ≤ 1071 \leq \text{mod} \leq 10^7)。

输出格式

If the first player wins, print "1" and the lexicographically minimum string _s_1 he has to write to win. If the second player wins, print the single number "2".

如果先手玩家获胜,输出“1”以及他为获胜必须写出的字典序最小的字符串 s1s_1;如果后手玩家获胜,则仅输出单个数字“2”。

输入输出样例

  • 输入#1

    1 10 7

    输出#1

    2
  • 输入#2

    4 0 9

    输出#2

    1 000000001

说明/提示

The lexical comparison of strings is performed by the < operator in modern programming languages. String x is lexicographically less than string y if exists such i (1 ≤ i ≤ 9), that x__i < y__i, and for any j (1 ≤ j < i) x__j = y__j. These strings always have length 9.

现代编程语言中,字符串的字典序比较通过 < 运算符实现。字符串 xx 在字典序上小于字符串 yy,当且仅当存在某个 ii(1 ≤ i ≤ 91 \le i \le 9),使得 xi < yix_i < y_i,且对任意 jj(1 ≤ j < i1 \le j < i)均有 xj = yjx_j = y_j。这些字符串的长度恒为 9。

输入解题思路,AI测评打分。不知道怎么写?

首页