UVa 550 - Multiplying by Rotation
来源:互联网 发布:巴宝莉风衣真假 知乎 编辑:程序博客网 时间:2024/04/28 03:22
Multiplying by Rotation
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 49 7 417 14 12
Sample Output
624
Miguel A. Revilla
1998-03-10
#include <iostream>#include <string.h>using namespace std;int main(){ int i,j,n,m,s,bas,t; int p,sum,end; while(cin>>bas>>n>>m) { p=sum=0; end=n; while(1) { sum++; t=n*m+p; p=0; n=t%bas; p=t/bas; if(n==end&&p==0) { break; } } cout<<sum<<endl; } 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
- Objective-C基础教程一
- FLTK学习-2-新手入门参考
- 用等比数列解析伪列level的另一个作用
- arx记录,长期更新
- Android OpenGL基础教程 2
- UVa 550 - Multiplying by Rotation
- 网页浏览器的“内核”与“外壳”[z]
- zendframework数据库操作
- HDU 1142 A Walk Through the Forest
- 浮点数反汇编的学习
- Linux编程里getopt_long_only函数用法详解
- 系统编程之网络编程 tcp
- C++内存分配
- 【评论】微软推自主品牌WP手机:拔苗助长恐令诺基亚倒戈