hdu 4485 B-Casting (数学)
来源:互联网 发布:ps软件下载官方网 编辑:程序博客网 时间:2024/05/29 13:18
B-Casting
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 370 Accepted Submission(s): 187
Problem Description
Casting around for problems leads us to combine modular arithmetic with different integer bases, particularly the problem of computing values modulo b-1, where b is the base in which the value is represented. For example,
782910 mod 9 = 8,
377777777777777738 mod 7 = 6
1234567 mod 6 = 3
(Note that 377777777777777738 = 112589990684261910 and 1234567 = 2287510.)
Your job is to write a program that reads integer values in various bases and computes the remainder after dividing these values by one less than the input base.
782910 mod 9 = 8,
377777777777777738 mod 7 = 6
1234567 mod 6 = 3
(Note that 377777777777777738 = 112589990684261910 and 1234567 = 2287510.)
Your job is to write a program that reads integer values in various bases and computes the remainder after dividing these values by one less than the input base.
Input
The first line of input contains a single integer P, (1 <= P <= 1000) , which is the number o data sets that follow. Each data set should be processed identically and independently.
Each data set consists of a single line of input containing three space-separated values. The first is an integer which is the data set number. The second is an integer which is the number, B (2 <= B <= 10), denoting a numeric base. The third is an unsigned number, D, in base B representation. For this problem, the number of numeric characters in D will be limited to 10,000,000.
Each data set consists of a single line of input containing three space-separated values. The first is an integer which is the data set number. The second is an integer which is the number, B (2 <= B <= 10), denoting a numeric base. The third is an unsigned number, D, in base B representation. For this problem, the number of numeric characters in D will be limited to 10,000,000.
Output
For each data set there is a single line of output. It contains the data set number followed by a single space which is then followed by the remainder resulting from dividing D by (B-1).
Sample Input
41 10 78292 7 1234563 6 4325040235451124 8 37777777777777773
Sample Output
1 82 33 14 6
对于一个b进制的数,每一位分别是an,...a5,a4,a3,a2,a1,a0;
则变成十进制就是((b)^0*a0)+((b^1)*a1)+......((b^n)*an);
对于其中的一项 求(b^k *ak )%(b-1)
用t=b-1
则变成((t+1)^k*ak)%t
而(t+1)^k%t 展开后显然只剩1了,其他都是t的倍数
所以(b^k *ak )%(b-1)=ak%(b-1)
.......
#include<stdio.h>#include<string.h>#include<iostream>#include<string>#include<algorithm>using namespace std;int p,a,b;char s[10000000+1];int main(){ scanf("%d",&p); while(p--) { scanf("%d%d%s",&a,&b,s); int j=0; int ans=0; int l=strlen(s)-1; for(int i=l;i>=0;i--) { ans+=(s[i]-'0')%(b-1); ans%=b-1; } printf("%d %d\n",a,ans); } return 0;}
- hdu 4485 B-Casting (数学)
- hdu 4485 B-Casting
- HDU 4485 B-Casting
- HDU 4485 B-Casting (基础题)
- 简单数学题-hdu-4485-B-Casting
- UVALive 6173|HDU 4485|B-Casting|水体
- HDU - 2035 人见人爱A^B(数学)
- Uva 6173 B-Casting
- hdu4485 B-Casting(mod运算)
- Casting
- HDU 1877:又一版 A+B【数学】
- 求 a^b(数学)
- hdu 5109 Alexandra and A*B Problem(取模,枚举,数学数论)
- hdu 1061(数学)
- hdu 4153(数学)
- hdu 1403 (数学)
- hdu 1027(数学)
- hdu 1071 (数学)
- Python编码问题总结
- using namespace std 说明
- Filesystem Enumeration using Redis and Lua
- Java中文乱码处理
- jQuery中常用的函数方法总结
- hdu 4485 B-Casting (数学)
- C++程序员我的学习指南
- 工薪族如何发家致富
- 一个基于jQuery写的弹窗效果(附源码)
- 冒泡排序算法原理及实现
- android的权限管理该怎么做?
- UVA610 Street Directions
- Oracle内连接、外连接、右外连接、全外连接小总结
- Linux网络设备驱动概述