number theory 算法竞赛入门经典 刘汝佳

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

number theory

575 - Skew Binary

When a number is expressed in decimal, the k-th digit represents a multiple of 10k. (Digits are numbered from right to left, where the least significant digit is number 0.) For example,

When a number is expressed in binary, the k-th digit represents a multiple of 2k. For example,

In skew binary, the k-th digit represents a multiple of 2k+1 - 1. The only possible digits are 0 and 1, except that the least-significant nonzero digit can be a 2. For example,

The first 10 numbers in skew binary are 0, 1, 2, 10, 11, 12, 20, 100, 101, and 102. (Skew binary is useful in some applications because it is possible to add 1 with at most one carry. However, this has nothing to do with the current problem.)

Input

The input file contains one or more lines, each of which contains an integer n. If n = 0 it signals the end of the input, and otherwise n is a nonnegative integer in skew binary.

Output

For each number, output the decimal equivalent. The decimal value of n will be at most 231 - 1 = 2147483647.

Sample Input

10120

200000000000000000000000000000

10

1000000000000000000000000000000

11

100

11111000001110000101101102000

Sample Output

44

2147483646

3

2147483647

4

7

1041110737

10110 - Light, more light

There is man named "mabu" for switching on-off light in our University. He switches on-off the lights in a corridor. Every bulb has its own toggle switch. That is, if it is pressed then the bulb turns on. Another press will turn it off. To save power consumption (or may be he is mad or something else) he does a peculiar thing. If in a corridor there is `n' bulbs, he walks along the corridor back and forth `n' times and in i'th walk he toggles only the switches whose serial is divisable by i. He does not press any switch when coming back to his initial position. A i'th walk is defined as going down the corridor (while doing the peculiar thing) and coming back again.

Now you have to determine what is the final condition of the last bulb. Is it on or off?

The Input

The input will be an integer indicating the n'th bulb in a corridor. Which is less then or equals 2^32-1. A zero indicates the end of input. You should not process this input.

The Output

Output "yes" if the light is on otherwise "no" , in a single line.

Sample Input

3

6241

8191

Sample Output

no

yes

no

550 - Multiplying by Rotation

Warning: Not all numbers in this problem are decimal numbers!

Multiplication of natural numbers in general is a cumbersome operation. In some cases however the product can be obtained by moving the last digit to the front.

Example: 179487 * 4 = 717948

Of course this property depends on the numbersystem you use, in the above example we used the decimal representation. In base 9 we have a shorter example:

17 * 4 = 71 (base 9)

as (9 * 1 + 7) * 4 = 7 * 9 + 1

Input

The input for your program is a textfile. Each line consists of three numbers separated by a space: the base of the number system, the least significant digit of the first factor, and the second factor. This second factor is one digit only hence less than the base. The input file ends with the standard end-of-file marker.

Output

Your program determines for each input line the number of digits of the smallest first factor with the rotamultproperty. The output-file is also a textfile. Each line contains the answer for the corresponding input line.

Sample Input

10 7 4

9 7 4

17 14 12

Sample Output

6

2

4

568 - Just the Facts

The expression N!, read as ``N factorial," denotes the product of the first N positive integers, where N is nonnegative. So, for example,

For this problem, you are to write a program the last non-zero digit of any factorial for

( ). For example, if your program is asked to compute the last nonzero digit of 5!, your program should produce ``2" because 5! = 120, and 2 is the last nonzero digit of 120.

Input

Input to the program is a series of nonnegative integers not exceeding 10000, each on its own line with no other letters, digits or spaces. For each integer N, you should read the value and compute the last nonzero digit of N!.

Output

相关文档
最新文档