题目链接:http://poj.org/problem?id=2305

ime Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5326   Accepted: 2267

Description

Given a base b and two non-negative base b integers p and m, compute p mod m and print the result as a base b integer. p mod m is defined as the smallest non-negative integer k such that p = a*m + k for some integer a.

Input

Input consists of a number of cases. Each case is represented by a line containing three unsigned integers. The first, b, is a decimal number between 2 and 10. The second, p, contains up to 1000 digits between 0 and b-1. The third, m, contains up to 9 digits between 0 and b-1. The last case is followed by a line containing 0.

Output

For each test case, print a line giving p mod m as a base-b integer.

Sample Input

2 1100 101
10 123456789123456789123456789 1000
0

Sample Output

10
789
 #include<stdio.h>
#include<iostream>
#include<cstring>
#include<limits.h>
#include<queue>
using namespace std;
char a[],b[];
long long c,e;//开int会WA
int len1,len2;
int f[];
int change1()//把b转换成十进制//对的
{
int d=,i;
for(i=;i<len2;i++)
{
d=d*c+b[i]-'';
}
return d;
}
void change2()//把十进制e转化成目标进制输出
{
int i;
for(i=;i<;i++)
{
if(e<c)break;
f[i]=e%c;
e/=c;
}
f[i]=e;
int len3=i+;
for(i=len3-;i>=;i--)
{
if(i==len3-&&f[i]==&&len3!=)
continue;
else
cout<<f[i];
}
cout<<endl;
}
int main()
{
int i;
while(cin>>c&&c)
{
cin>>a>>b;
len1=strlen(a);
len2=strlen(b);
int d=change1();
//cout<<d<<endl;
e=;
for(i=;i<len1;i++)
{
e=e*c+a[i]-'';
e=e%d;
}
//cout<<e<<endl;
change2();
}
return ;
}

POJ 2305 Basic remains(进制转换)的更多相关文章

  1. POJ 2305:Basic remains 进制转换

    Basic remains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5221   Accepted: 2203 Des ...

  2. poj2305-Basic remains(进制转换 + 大整数取模)

    进制转换 + 大整数取模一,题意: 在b进制下,求p%m,再装换成b进制输出. 其中p为b进制大数1000位以内,m为b进制数9位以内二,思路: 1,以字符串的形式输入p,m; 2,转换:字符串-&g ...

  3. poj 2305(指定进制,大数取模)

    题意:输入一个进制b,在输入两个基于b进制的大整数 x,y ,求x%y的b进制结果. http://162.105.81.212/JudgeOnline/problem?id=2305 函数: Str ...

  4. POJ 1220 大数字的进制转换,偷下懒,用java

    题意为进制转换,Java的大数类就像是作弊 import java.math.BigInteger; import java.util.Scanner; public class Main { pub ...

  5. poj1220 (高精度任意进制转换)

    http://poj.org/problem?id=1220 高精度任意进制转换 代码是从discuss里找到的,据说是maigo神牛写的. 超精简!! 我自己第一写的时候,还把n进制先转成10进制, ...

  6. SQL Server 进制转换函数

    一.背景 前段时间群里的朋友问了一个问题:“在查询时增加一个递增序列,如:0x00000001,即每一个都是36进位(0—9,A--Z),0x0000000Z后面将是0x00000010,生成一个像下 ...

  7. [No000071]C# 进制转换(二进制、十六进制、十进制互转)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. JS中的进制转换以及作用

    js的进制转换, 分为2进制,8进制,10进制,16进制之间的相互转换, 我们直接利用 对象.toString()即可实现: //10进制转为16进制 ().toString() // =>&q ...

  9. 结合stack数据结构,实现不同进制转换的算法

    #!/usr/bin/env python # -*- coding: utf-8 -*- # learn <<Problem Solving with Algorithms and Da ...

随机推荐

  1. Linux下产生随机密码10方法

    有特殊符号的: cat /dev/urandom | tr -dc "a-zA-Z0-9_+\~\!\@\#\$\%\^\&\*"| fold -w 16 |head -n ...

  2. 关于preg_match()函数的一点小说明

    int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $ ...

  3. 几种主流浏览器内置http抓包工具软件使用方法

    对于学习网站的人或者相关编程人员,经常需要用到http抓包工具来跟踪网页,但主流抓包软件如httpwatch.httpanalyzerstdv都是收费的,破解版往往也不稳定.实际上现在很多浏览器都内置 ...

  4. jQ内容的强大,后面继续跟进...

    <script type="text/javascript" src="jQ/jquery.js"></script> <scri ...

  5. break位于内循环。作用于外循环

    outer:for(int i = 0; i < 4; ++i)  {       inner:for(int j = 0; j < 4; ++j)       {           S ...

  6. 用ES6语法和方式写gulp

    安装依赖模块 npm i -g gulp npm i gulp babel-core babel-preset-es2015 --save-dev 在创建文件 .babelrc(文件名) : (文件内 ...

  7. BIEE应用存储过程并从前台传参

    1.     RPD操作 1.1修改连接池属性 在连接脚本添加SQL,这里选择在查询前执行 新建SQL脚本

  8. 伪AP检测技术研究

    转载自:http://www.whitecell-club.org/?p=310 随着城市无线局域网热点在公共场所大规模的部署,无线局域网安全变得尤为突出和重要,其中伪AP钓鱼攻击是无线网络中严重的安 ...

  9. nodejs 中es5 模块的几种写法

    1. module.exports.func = function(){}  module.exports.field = ''; 第一种是逐个对api 和字段导出. 2. module.export ...

  10. linux driver module

    本文将对Linux系统中的sysfs进行简单的分析,要分析sysfs就必须分析内核的driver-model(驱动模型),两者是紧密联系的.在分析过程中,本文将以platform总线和spi主控制器的 ...