uva 550——Multiplying by Rotation
生活随笔
收集整理的這篇文章主要介紹了
uva 550——Multiplying by Rotation
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:在一個進制內 比如十進制下179487 * 4 = 717948和9進制下17 * 4 = 71 給定三個數,一個是進制,一個數是該組數的最后一個數字,另外一個則是該組數中的一個因數,問該組數中另一個因數是多少位數。
思路:由最后一位數和因數可以求出來前一位數的數字,然后依次類推,一直到第一位數等于最后一位數,實際上就是一個不斷模擬的過程。
code:
思路:由最后一位數和因數可以求出來前一位數的數字,然后依次類推,一直到第一位數等于最后一位數,實際上就是一個不斷模擬的過程。
code:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int cal(int ba,int la,int dv)
{
int cnt=0,t;
t=la*dv;
while (t!=la) //不斷算前前一位,直到其等于給定的最后一位
{
int qi=t/ba;
t%=ba;
cnt++;
t=dv*t+qi;
}
return cnt+1;
}
int main()
{
int ba,la,dv;
while (~scanf("%d%d%d",&ba,&la,&dv))
printf("%d\n",cal(ba,la,dv));
}
總結
以上是生活随笔為你收集整理的uva 550——Multiplying by Rotation的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 冰原守卫者龙的驯化值怎么提升
- 下一篇: 地下城与勇士好卡,怎么办