Multiplying by Rotation UVA550
来源:互联网 发布:戴尔豪斯大学知乎 编辑:程序博客网 时间:2024/04/24 13:26
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
一道简单的数论题目,题意大概是给你一个基数,尾数,乘数,找出这样一个数字这个数字乘以乘数是的最低位变换到最高位,其他的位向右移动一位,好比这串数字循环移位,并要求这个数字位数最少。。。
179487 * 4 = 717948(10进制)
4*7=28 28!=7 28/10=2 28=8;
4*8+2=34 34!=7 37/10=3 34=4;
4*4+3=19 19!=7 19/10=1 19=9;
4*9+1=37 37!=7 37/10=3 37=7;
4*7+3=31 31!=7 31/10=3 31=1;
4*1+3=7 7==7;(end)
则这个数为179487,6位数,输出6。
大家发现规律了么。。。用给出的末位乘上乘数后,求余得到的数是下一位,又可以用这个下一位乘上乘数加上进位看看是不是等于要求的末位。。感觉说的不清楚啊。。语言表达能力太弱。
#include<iostream>using namespace std;int main(){ int base,last,multi; while(cin>>base>>last>>multi) { int remain=0,num=0; int last1=last; while(1) { if(last==multi*last1+remain) { num++; break; } num++; int last2=last1; last1=(multi*last1+remain)%base; remain=(last2*multi+remain)/base; } cout<<num<<endl; } return 0;}
- UVa550 Multiplying by Rotation
- Multiplying by Rotation UVA550
- UVA550 Multiplying by Rotation
- UVA550 Multiplying by Rotation
- 550 - Multiplying by Rotation
- 550 - Multiplying by Rotation
- 550 - Multiplying by Rotation
- Multiplying by Rotation
- 550 - Multiplying by Rotation
- UVA Multiplying by Rotation
- Multiplying by Rotation
- Multiplying by Rotation
- uva 550 - Multiplying by Rotation
- Uva 550 - Multiplying by Rotation
- UvaOJ 550 - Multiplying by Rotation
- uva 550 - Multiplying by Rotation
- UVa 550 Multiplying by Rotation
- UVa 550 - Multiplying by Rotation
- hdu1199Color the Ball (线段树 段更新+离散化)
- ORA-01207:文件比控制文件更新 - 旧的控制文件
- chdir getcwd 函数的使用过程中出现的问题
- 抽象的意义
- 802.11n基础知识
- Multiplying by Rotation UVA550
- Hbase分布式的安装
- Java Thread 总结
- ZOJ 1086: Octal Factions
- mkisofs命令常用选项介绍
- 【解决Win7系统开机后无法进入的方法】
- Cracking the Coding Interview Chap1 Q1.1
- 美团笔试2014-美团网举行女子羽毛球比赛,前端组、后短租、手机组各派了三名运动员参加。比赛前,4名程序员在一起预测比赛结果。
- Oracle字符集的查看和修改