TOJ 3237.Change Base

题目链接:http://acm.tju.edu.cn/toj/showp3237.html


3237.    Change Base
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 592    Accepted Runs: 380



Given an integer m in base B (2 ≤ B ≤ 10) (m contains no more than 1000 digits), find the value of the integer m in base 10, output the result modulo 10007.

Input

The first line of the input is a single integer T representing the number of test cases. Then T lines follow. In each line there are two integers: B and m, separated by a single space.

Output

For each test cases, give your answer in a single line.

Sample Input

3
2 101
7 16532505605660160442
10 246234

Sample Output

5
4165
6066



Source: TJU Team Selection Contest 2009 (2)
Submit   List    Runs   Forum   Statistics


水题,pow也要模10007,或者每次叠加模10007;


#include 
#include 
#include 
#include 
#include 
using namespace std;
int main(){
	int base,n;
	int sum;
	//string num;
	scanf("%d",&n);
	while(n--){
		string num;
		cin>>base;
		cin>>num;
		//cout<=0;i--){
			sum=(sum+(num[i]-'0')*pow1)%10007;
			pow1=(pow1*base)%10007;
		}
		printf("%d\n",sum);
	}
}


你可能感兴趣的:(Toj水题)