1.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS10/11
* Problem: 550 Multiplying by Rotation
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=491
*
* @author Fabian Liebl
* @version 1.0, 10/06/2010
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.212
*/

import java.io.*;

public class Main {

public static void main(String[] args) throws IOException {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));

int base;
int digit, lastDigit;
int mul, over;
int count;
int factor;

String line = inputReader.readLine();
String[] splitLine;

while (line != null) {
splitLine = line.split(" ");

base = Integer.parseInt(splitLine[0]);
lastDigit = Integer.parseInt(splitLine[1]);
factor = Integer.parseInt(splitLine[2]);

digit = lastDigit;
over = 0;
count = 0;

do {
mul = (digit * factor) + over;
digit = mul % base;
over = mul / base;
count++;
} while (!((digit == lastDigit) && (over == 0)));

System.out.println(count);

line = inputReader.readLine();
}

}

}

2.
/**
* FWP: Ausgewaehlte Probleme aus dem ACM (SS10)
*
* Method: Math: Bases
* Problem: 550 - MultiplyingByRotation
* Accepted: 0.328
* @author Evgeni Pavlidis
*
*/
import java.util.*;
import java.io.*;

class Main {

public static void main(String...args)
{
Scanner scanner = new Scanner(System.in);

int base, firstFactor, secondFactor, carry, c, digit;

while(scanner.hasNextInt())
{
base = scanner.nextInt();
firstFactor = scanner.nextInt();
secondFactor = scanner.nextInt();

c = 0;
carry = 0;
digit = firstFactor;
do
{
digit = digit * secondFactor + carry;
carry = digit / base;
digit = digit % base;
//System.out.printf(" ===> %d %d carry = %d\n", digit, secondFactor, carry);
c++;

}while(carry > 0 || digit != firstFactor);

System.out.println(c);
}
}
}