题目链接:http://acm.tju.edu.cn/toj/showp3237.html
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)
水题,pow也要模10007,或者每次叠加模10007;
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
int main(){
int base,n;
int sum;
//string num;
scanf("%d",&n);
while(n--){
string num;
cin>>base;
cin>>num;
//cout<<num<<endl;
long long pow1=1;
sum=0;
int length=num.length();
//cout<<length;
for(int i=length-1;i>=0;i--){
sum=(sum+(num[i]-'0')*pow1)%10007;
pow1=(pow1*base)%10007;
}
printf("%d\n",sum);
}
}