Trang

Thứ Năm, 30 tháng 12, 2010

3237. Change Base

3237. Change Base
http://acm.tju.edu.cn/toj/showp3237.html

import java.io.*; public class Main { /** * @author hunglee */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); int T, b; String s, st[]; T = Integer.parseInt(in.readLine()); while (T-- > 0) { st = in.readLine().split(" "); b = Integer.parseInt(st[0]); s = st[1]; long res = 0; for (int i = 0; i < s.length(); ++i) res = (res * b + s.charAt(i) - '0') % 10007; System.out.println(res); } } }

Không có nhận xét nào:

Đăng nhận xét