UVA - 550 Multiplying by Rotation
来源:互联网 发布:php获取post json数据 编辑:程序博客网 时间:2024/04/29 00:52
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
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 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 49 7 417 14 12
Sample Output
624题意:就是将最后一位数变为第一位数,需要几次?步骤如下:179487 * 4 = 717948(10进制)4*7=28 28!=7 28/10=2 28%10 =84*8+2=3434!=7 34/10=3 34%10=4; 4*4+3=1919!=7 19/10=1 19%10=9; 4*9+1=3737!=7 37/10=3 37%10=7; 4*7+3=3131!=7 31/10=3 31%10=1; 4*1+3=77==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;}
0 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
- 矩阵十题【九】 HDU 2157 How many ways??
- boost::split
- 字符串-03. 字符串的冒泡排序(20)
- HDU_1862 EXCEL排序
- COURSES+POJ+二分图裸题
- UVA - 550 Multiplying by Rotation
- JQuery Upload File插件上传文件提示 Empty file upload result
- FZU_Problem 2171 防守阵地 II
- Eclipse构建Maven项目
- maven + jetty + eclipse热部署(hot code)
- iptables火墙
- 判断字符串中只含有字母和问题
- Metronic V3.1.3 Responsive Admin Dashboard Template build with Twitter Bootstrap 3.2.0
- C与C++中标准输入实现方式上的一点区别