当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1796:Extra Terrestrial PISA Test

题目描述
Background
On the planet Divido teachers have a serious problem. Due to the spread of calculators the students cannot do long division with pencil and paper any longer. But now the planetarian government has announced a test for all students in basic schools to test their math skills. Because it has to be a multiple choice test the students only have to calculate the length of the period when dividing two numbers. Your task is to write a program which calculates the right solutions in advance to ease the correction of the test. An additional problem occurs because not all intelligent species on Divido have the same number of fingers and thus their systems of numbers have different bases.

Problem
You are given a base b, a numerator x, and a denominator y, the latter of which are integers to the base b.Then calculate the length of the period in the base b expansion of the fraction q = x/y. Remember that the digits of the base b expansion of the the rational number q are the coefficients of the powers of the base:
q = qnqn-1...q0.q-1q-2...=Σ-∞<=i<=nqibi
Here are some examples:
110/210=0.510,13/103=0.13,210/1110=0.181818...10= 0.(18)10
In the first two examples, there is a finite base b expansion of the fraction, meaning that all digits that follow are zero. In that case, we say that the length of the period is zero. Note that one could as well express the first example as 0.4(9)10 with a period length of one, but that is not what we want.
In the third example, however, the period length is unambiguously two.
输入解释
The first line contains the number of fractions. For each fraction you are first given the base b as a decimal number with 2 <= b <= 36, and then the numerator x and the denominator y of the fraction to that base separated by single blanks. It is guaranteed that the denominator satisfies 0 < y <= 100 00010. Digits not in the range of 0 . . . 9 are represented by letters starting from "a" or "A" in the usual way, where case does not matter.
输出解释
The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the length of the period in the base b expansion of x/y , but make sure to print the length as a decimal number. Terminate the output for the scenario with a blank line.
输入样例
4
10 1 2
3 1 10
10 2 11
36 HI ho
输出样例
Scenario #1:
0

Scenario #2:
0

Scenario #3:
2

Scenario #4:
13

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-1796

最后修改于 2020-10-29T06:14:11+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 30000