题目链接: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. 向python3进发

    在Python2.x中,交互输入有input和raw_input两种方法 input-----------tmd是个坑,就别用 raw_input------把输入无论是Int或str都当做是str处 ...

  2. Url Rewrite IIS 配置

    在configuration节点下 <system.webServer> <rewrite> <rules> <rule name="rD" ...

  3. JsSIP.UA.JsSIP 总是返回错误:422 Session Interval Too Small

    在JsSIP 中 JsSIP.UA.call 总是 返回错误:422 Session Interval Too Small 关于错详情在这篇文章中解释的比较详尽:http://www.cnblogs. ...

  4. Unity3DGUI:常用控件

  5. HDU 5877 Weak Pair

    $dfs$序,线段树. 可以统计每一个节点作为$root$的子树上对答案的贡献,可以将树转换成序列.问题就变成了一段区间上求小于等于某个值的数有几个.用线段树记录排好序之后的区间序列,询问的时候,属于 ...

  6. PyQt界面编程应用与实践

    一个典型的GUI应用程序可以抽象为:主界面(菜单栏.工具栏.状态栏.内容区域),二级界面(模态.非模态),信息提示(Tooltip),程序图标等组成.本篇根据作者使用PyQt5编写的一个工具,介绍如何 ...

  7. Office下载地址

    文件名cn_office_professional_plus_2016_x86_x64_dvd_6969182.isoSHA1277926A41B472EE38CA0B36ED8F2696356DCC ...

  8. C# 语言规范_版本5.0 (第17章 特性)

    1. 特性 C# 语言的一个重要特征是使程序员能够为程序中定义的实体指定声明性信息.例如,类中方法的可访问性是通过使用 method-modifiers(public.protected.intern ...

  9. String、StringBuffer和StringBuilder区别及性能分析

    1.性能比较:StringBuilder >  StringBuffer  >  String 2.String <(StringBuffer,StringBuilder)的原因 S ...

  10. centos php nginx 添加到service

    1. nginx A. # vi /etc/init.d/nginx B. #!/bin/sh # Comments to support chkconfig on RedHat Linux # ch ...