Basic remains(高精度)
来源:互联网 发布:淘宝快递助手怎么用 编辑:程序博客网 时间:2024/06/15 17:19
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 10110 123456789123456789123456789 10000
Sample Output
10789
解题思路
都化成十进制,得到余数后再化成需要的进制;
余数为0时单独输出下,
AC代码
#include<stdio.h>#include<string.h>int main(){ int n, i; while(scanf("%d", &n), n) { char str1[1005], str2[15]; scanf("%s%s", str1, str2); //都以字符串输入,方便的多 int len1 = strlen(str1), len2 = strlen(str2); long long a = 0, b = 0; for(i = 0; i < len2; i++) //计算除数的十进制数 b = b * n + str2[i] - '0'; for(i = 0; i < len1; i++) { a = a * n + str1[i] - '0'; //被除数转化成十进制的同时,对除数取模,因为最后只要求余数 if(a >= b) a %= b; } if(a == 0) { printf("0\n"); continue; } int c[15]; for(i = 14; a != 0; i--) { c[i] = a % n; a /= n; } for(i++; i <= 14; i++) printf("%d", c[i]); printf("\n"); } return 0;}
0 0
- Basic remains(高精度)
- poj 2305 Basic remains 高精度取余
- Basic remains
- Basic remains
- POJ 2305 Basic remains (大数余)
- POJ 2305 Basic remains(JAVA练习)
- pku 2305 - Basic remains
- POJ2305:Basic remains
- POJ 2305 - Basic remains
- POJ2305 Basic remains
- UVa 10551 - Basic Remains
- poj2305 Basic remains
- POJ_2305 Basic remains
- POJ 2305 Basic remains .
- poj 2305 Basic remains java
- POJ 2305 Basic remains 笔记
- 计算余数问题/poj2305 Basic remains
- POJ 2305:Basic remains 进制转换
- 呵呵
- DOM小结
- HDU4910 (数论:Miller_Rabin+一个定理)
- 杭电1106 排序
- 写在最前面
- Basic remains(高精度)
- 创建不被杀死的service
- Unable to determine the workspace. You may be able to correct this by running 'tf workspaces /collec
- 配置-如何用ABAP实现自动发送外部邮件
- 9家知名P2P联合送现金,金额之巨震惊业界!
- Acceptor-Connector模式一(Acceptor的工作)V2.0
- poj 1088 滑雪 (记忆化 Dp)
- Win7 快捷方式变成浏览器图标解决
- 存储与服务器的连接方式对比(DAS,NAS,SAN)