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
题意概述:给定一个以B为基数的整数,将这个数转化为以10为基数的整数,将所得的数对10007取模,将取模后的结果输出。需要注意的是,题目中指出给定的整数可能会很长,可能会有1000个位。
解题思路:从题目概述中很容易就知道,这个题目必须使用字符串进行模拟,否则不能做。题目主要用到模运算的一些性质,了解即可。

源代码:

#include<string>
#include<iostream>
using namespace std;
int main()
{
    int T,B,L,R;
    string s;
    cin>>T;
    while(T--)
    {
         R=0;
         cin>>B>>s;
         for(int i=0;i<s.size();++i)
         {
               //过程中就可以对每一次结果进行取模,避免出现结果超出int型的范围 
               R=(R*B+s[i]-48)%10007; 
         }
         cout<<R<<endl;
    }
    return 0;
}

Change Base的更多相关文章

  1. lnmp平台菜鸟入门级笔记

                  LNMP平台搭建 Mysql安装  MySQL安装 回复收藏  分享    1 下载MySQL数据库l到/usr/local/src/[root@xin tmp]# cd ...

  2. python中from module import * 的一个陷阱

    from module import *把module中的成员全部导到了当前的global namespace,访问起来就比较方便了.当然,python style一般不建议这么做,因为可能引起nam ...

  3. centos6.5 mysql开机启动

    可参考:centos6.5 nginx开机启动 /etc/init.d/下添加mysqld文件,内容如下: #!/bin/sh # Copyright Abandoned TCX DataKonsul ...

  4. python之import机制

    1. 标准 import        Python 中所有加载到内存的模块都放在 sys.modules .当 import 一个模块时首先会在这个列表中查找是否已经加载了此模块,如果加载了则只是将 ...

  5. 2016.10.08,英语,《Verbal Advantage》Level1 Unit1-4

    这本书学的很辛苦,总共10个Level,每个Level有5个Unit,每个Unit10个单词,实际上自己差不多一天才能学完1个Unit10个单词.(当然,一天我只能花大约1个小时左右在英语上) 而且跟 ...

  6. lnmp安装--linux通过tar.gz源码包安装mysql

    mysql版本:5.6 [http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz] [http://dev.mysql.com/get ...

  7. 编译错误“The run destination My Mac 64-bit is not valid for Running the scheme '***',解决办法

    1. iOS APP Project or  Mac APP Project编译错误提示:
“The run destination My Mac 64-bit is not valid for Ru ...

  8. 深度解析MySQL启动时报“The server quit without updating PID file”错误的原因

    很多童鞋在启动mysql的时候,碰到过这个错误, 首先,澄清一点,出现这个错误的前提是:通过服务脚本来启动mysql.通过mysqld_safe或mysqld启动mysql实例并不会报这个错误. 那么 ...

  9. .Net大局观(2).NET Core 2.0 特性介绍和使用指南

    .NET Core 2.0发布日期:2017年8月14日 前言 这一篇会比较长,系统地介绍了.NET Core 2.0及生态,现状及未来计划,可以作为一门技术的概述来读,也可以作为学习路径.提纲来用. ...

随机推荐

  1. 【转】【C#】判断当前操作系统

    写一个判断操作系统的工具类OSHelper.cs public class OSHelper { // 获取操作系统ID public static System.PlatformID GetPlat ...

  2. Jackson2.1.4 序列化对象时对属性的过滤

    //对field(所有字段)进行过滤 //对get方法进行过滤 //对isBoolean这样的方法进行过滤 //里面的具体配置有 ANY,DEFAULT,NON_PRIVATE,NONE,PROTEC ...

  3. pku1204 Word Puzzles AC自动机 二维字符串矩阵8个方向找模式串的起点坐标以及方向 挺好的!

    /** 题目:pku1204 Word Puzzles 链接:http://poj.org/problem?id=1204 题意:给定一个L C(C <= 1000, L <= 1000) ...

  4. 如果通过html 链接打开app

    https://my.oschina.net/liucundong/blog/354029 <!doctype html> <html> <head> <me ...

  5. Translating between qplot and base graphics

    Translating between qplot and base graphics Description There are two types of graphics functions in ...

  6. IE和Firefox之间的JavaScript差异

    这篇文章中,我会略述一下 Internet Explorer 和 Firefox 在 JavaScript 语法上不同的几 个方面. 1. CSS “float” 属性 获取给定对象的特定 CSS 属 ...

  7. Oracle中的job的定时任务

    Oracle job有定时执行的功能,可以在指定的时间点或每天的某个时间点自行执行任务. 一.查询系统中的job,可以查询视图 --相关视图 select * from dba_jobs; selec ...

  8. C++类的成员函数的形参列表后面的const

    看到(C++ Primer)类的成员函数这里,突然对成员函数形参列表后面的const感到迷惑. 因为书中开始说是修饰隐含形参this的,然后又说是声明该函数是只读的. 大为不解! 翻资料.找人讨论.. ...

  9. motion的移植和使用

    说明: motion主页:http://www.lavrsen.dk/foswiki/bin/view/Motion motion下载地址:http://sourceforge.net/project ...

  10. 双卡手机怎么指定SIM卡打电话

    双卡手机如何指定SIM卡打电话 package com.example.dualsimtest; import android.app.Activity; import android.content ...