Change Base
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的更多相关文章
- lnmp平台菜鸟入门级笔记
LNMP平台搭建 Mysql安装 MySQL安装 回复收藏 分享 1 下载MySQL数据库l到/usr/local/src/[root@xin tmp]# cd ...
- python中from module import * 的一个陷阱
from module import *把module中的成员全部导到了当前的global namespace,访问起来就比较方便了.当然,python style一般不建议这么做,因为可能引起nam ...
- centos6.5 mysql开机启动
可参考:centos6.5 nginx开机启动 /etc/init.d/下添加mysqld文件,内容如下: #!/bin/sh # Copyright Abandoned TCX DataKonsul ...
- python之import机制
1. 标准 import Python 中所有加载到内存的模块都放在 sys.modules .当 import 一个模块时首先会在这个列表中查找是否已经加载了此模块,如果加载了则只是将 ...
- 2016.10.08,英语,《Verbal Advantage》Level1 Unit1-4
这本书学的很辛苦,总共10个Level,每个Level有5个Unit,每个Unit10个单词,实际上自己差不多一天才能学完1个Unit10个单词.(当然,一天我只能花大约1个小时左右在英语上) 而且跟 ...
- 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 ...
- 编译错误“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 ...
- 深度解析MySQL启动时报“The server quit without updating PID file”错误的原因
很多童鞋在启动mysql的时候,碰到过这个错误, 首先,澄清一点,出现这个错误的前提是:通过服务脚本来启动mysql.通过mysqld_safe或mysqld启动mysql实例并不会报这个错误. 那么 ...
- .Net大局观(2).NET Core 2.0 特性介绍和使用指南
.NET Core 2.0发布日期:2017年8月14日 前言 这一篇会比较长,系统地介绍了.NET Core 2.0及生态,现状及未来计划,可以作为一门技术的概述来读,也可以作为学习路径.提纲来用. ...
随机推荐
- 【Unity笔记】UGUI的自动布局功能
一些RectTransform的物体(UGUI元素)已经实现了ILayoutElement接口,如Image. 如果一个RectTransform的物体(UGUI元素)的其中一个组件实现了ILayou ...
- EFM32 DMA/PRS例程
/**************************************************************************//** * @file * @brief H ...
- stm8s + si4463 寄存器配置
/***********************************************函 数: main功 能: 程序入口输 入: /输 出: /描 述: /**************** ...
- salt '*' state.highstate 报错找不到文件,环境如下No Top file or master_tops data matches found.
salt '*' state.highstate 报错找不到文件,环境如下No Top file or master_tops data matches found. file_roots: b ...
- FFmpeg API变化
可以查看doc目录下的APIchanges和根目录下的Changelog 去掉了ffserver程序 'avcodec_register_all' is deprecated 还有av_regis ...
- Fork of LGPL version of JPedal
https://github.com/on-site/JPedal —————————————————————————————————————————————————————————————————— ...
- 关于Cocos2d-x有些头文件无法引入或者类显示无法打开
选中工程右键“属性”->"配置属性“->"c/c++"->"常规”->"附加包含目录"中添加“”$(EngineRo ...
- 仿教程 小爬虫抓取imooc数据
慕课网的nodejs教程:http://www.imooc.com/learn/348 这人讲的很赞,特别是在事件驱动这点上,耳目一新. 视频略老,所以demo有些过时了,摸索着写了一个自己的小程序. ...
- ffmpeg avformat_open_input返回失败的解决办法
用ffmpeg做的第一个程序,参考网上的代码,就出现了一些问题,其中avformat_open_input返回失败. 下面是我在网上收集到的失败信息的相关解决: /////////////////// ...
- myslq的索引类型为MyISAM和BDB的表:复合索引下的自增长
本文源自:http://www.himigame.com/mysql/781.html 3.6.9. 使用AUTO_INCREMENT 可以通过AUTO_INCREMENT属性为新的行产生唯一的标识: ...