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 <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);
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值