博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FZU 2102 Solve equation 多进制计算
阅读量:6493 次
发布时间:2019-06-24

本文共 2062 字,大约阅读时间需要 6 分钟。

Solve equation
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

You are given two positive integers A and B in Base C. For the equation:

 

A=k*B+d

 

We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in this problem, we want to maximize k.

 

For example, A="123" and B="100", C=10. So both A and B are in Base 10. Then we have:

(1) A=0*B+123

(2) A=1*B+23

As we want to maximize k, we finally get one solution: (1, 23)

 

The range of C is between 2 and 16, and we use 'a', 'b', 'c', 'd', 'e', 'f' to represent 10, 11, 12, 13, 14, 15, respectively.

Input

The first line of the input contains an integer T (T≤10), indicating the number of test cases.

 

Then T cases, for any case, only 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume that in Base 10, both A and B is less than 2^31.

Output

For each test case, output the solution “(k,d)” to the equation in Base 10.

Sample Input

32bc 33f 16123 100 101 1 2

Sample Output

(0,700)(1,23)(1,0) 每一位的数要乘进制 不要只是乘了10
#include 
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define FIN freopen("input.txt","r",stdin);#define FOUT freopen("output.txt","w",stdout);#define INF 0x3f3f3f3f#define INFLL 0x3f3f3f3f3f3f3f#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1typedef long long LL;typedef pair
PII;const int MAXN = 1000 + 5;char A[MAXN];char B[MAXN];int getnum(char a){ if(a >= '0' && a <= '9') return a - '0'; else return a - 'a' + 10;}int main(){ //FIN int T, C; scanf("%d", &T); while(T--){ scanf("%s%s", A, B); scanf("%d", &C); int lenA = strlen(A); int lenB = strlen(B); int numA = 0, numB = 0; for(int i = 0;i < lenA; i ++){ numA = numA * C + getnum(A[i]); } for(int i = 0;i < lenB; i ++){ numB = numB * C + getnum(B[i]); } //cout<
<<" "<
<

  

转载于:https://www.cnblogs.com/Hyouka/p/5790896.html

你可能感兴趣的文章
Libpcap tutorial-02
查看>>
java servlet简介-01
查看>>
中文乱码问题的处理
查看>>
Windows10 远程桌面连接失败,报CredSSP加密oracle修正错误解决办法
查看>>
egit在pull的时候出错
查看>>
Zabbix 中使用 Percona Monitoring Plugins 监控 MySQL
查看>>
我的友情链接
查看>>
5.Struts2-Struts标签
查看>>
各种技术综合总结(一)
查看>>
Filter案例用户自动登录学习笔记
查看>>
阿里云内网和公共NTP服务器
查看>>
c++ 正则表达式邮箱
查看>>
C 提高1 内存四区 变量本质 栈开口方向 指针铁律1
查看>>
QT windows平台安装
查看>>
Outlook 2003 邮件不能显示图片
查看>>
1+1*2+1*2*3+1*2*3*n数列的求和算法
查看>>
异常模拟测试 -- 场景抽象及解决方案
查看>>
Gradle之旅-can not find tools.jar问题解决
查看>>
JavaScript_navigator
查看>>
apache配置文件详解
查看>>