UVA - 550 Multiplying by Rotation
2014-08-11 15:43
483 查看
Warning: Not all numbers in this problem are decimal numbers!
Multiplication of natural numbers in general is a cumbersome operation. In somecases 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 aboveexample 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
base. The input file ends with the standardend-of-file marker.
Multiplication of natural numbers in general is a cumbersome operation. In somecases 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 aboveexample 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 thebase. The input file ends with the standardend-of-file marker.
Output
Your program determines for each input line the number of digits of the smallest first factor withthe rotamultproperty. The output-file is also a textfile. Each line contains the answer for thecorresponding input line.Sample Input
10 7 4 9 7 4 17 14 12
Sample Output
6 2 4 题意: 就是将最后一位数变为第一位数,需要几次? 步骤如下:179487 * 4 = 717948(10进制)4*7=28 28!=7 28/10=2 28%10 =84*8+2=34 34!=7 34/10=3 34%10=4;4*4+3=19 19!=7 19/10=1 19%10=9;4*9+1=37 37!=7 37/10=3 37%10=7;4*7+3=31 31!=7 31/10=3 31%10=1;4*1+3=7 7==7;(end)则这个数为179487,6位数,输出6。
#include<iostream> #include<stdio.h> #include<string.h> using namespace std; int main(){ int jz; int last; int cs; int n = 0; while(scanf("%d%d%d",&jz,&last,&cs) != EOF) { int ys = 0; int n = 0; int ls = last; for(;;) { if(ls*cs + ys == last) { n ++ ; break; } n ++ ; int l = ls; ls = (cs * ls + ys) % jz; ys = (cs * l + ys) / jz; } printf("%d\n",n); } return 0; }
相关文章推荐
- UVa 550 - Multiplying by Rotation
- UVa 550 Multiplying by Rotation (模拟乘法)
- UVA 550 - Multiplying by Rotation
- UVA - 550 Multiplying by Rotation 公式题
- uva 550 Multiplying by Rotation(模拟)
- UVA - 550 Multiplying by Rotation
- Uva 550 - Multiplying by Rotation
- UVA - 550 Multiplying by Rotation
- UVa 550: Multiplying by Rotation
- uva 550 - Multiplying by Rotation
- UVa 550 - Multiplying by Rotation
- UVA 550 - Multiplying by Rotation
- UVa 550 - Multiplying by Rotation
- UVA 550 Multiplying by Rotation (简单递推)
- uva 550——Multiplying by Rotation
- UVa 550 Multiplying by Rotation
- UVA - 550 Multiplying by Rotation
- uva 550 - Multiplying by Rotation
- UVa550 Multiplying by Rotation
- Multiplying by Rotation UVA550