http://poj.org/problem?id=2305
//package poj2305; import java.io.*; import java.math.*; import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner cin = new Scanner( new BufferedInputStream( System.in ) ); BigInteger p, m, ans; String str; int b; while( cin.hasNext() ){ b = cin.nextInt(); if( b == 0 ) break; p = cin.nextBigInteger( b ); m = cin.nextBigInteger( b ); ans = p.mod( m ); str = ans.toString( b ); System.out.println( str ); } } }