编程介的小学生 2019-09-14 02:49 采纳率: 20.5%
浏览 120

Extra Terrestrial PISA Test 代码的做法

Description

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.
Input

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.
Output

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.
Sample Input

4
10 1 2
3 1 10
10 2 11
36 HI ho
Sample Output

Scenario #1:
0

Scenario #2:
0

Scenario #3:
2

Scenario #4:
13

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 fesafe材料库问题
    • ¥35 beats蓝牙耳机怎么查看日志
    • ¥15 Fluent齿轮搅油
    • ¥15 八爪鱼爬数据为什么自己停了
    • ¥15 交替优化波束形成和ris反射角使保密速率最大化
    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统