博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1331 Multiply
阅读量:5921 次
发布时间:2019-06-19

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

Multiply
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 5179   Accepted: 2773

Description

6*9 = 42" is not true for base 10, but is true for base 13. That is, 6(13) * 9(13) = 42(13) because 42(13) = 4 * 131 + 2 * 130 = 54(10). 
You are to write a program which inputs three integers p, q, and r and determines the base B (2<=B<=16) for which p * q = r. If there are many candidates for B, output the smallest one. For example, let p = 11, q = 11, and r = 121. Then we have 11(3) * 11(3) = 121(3) because 11(3) = 1 * 31 + 1 * 30 = 4(10) and 121(3) = 1 * 32 + 2 * 31 + 1 * 30 = 16(10). For another base such as 10, we also have 11(10) * 11(10) = 121(10). In this case, your program should output 3 which is the smallest base. If there is no candidate for B, output 0. 

Input

The input consists of T test cases. The number of test cases (T ) is given in the first line of the input file. Each test case consists of three integers p, q, and r in a line. All digits of p, q, and r are numeric digits and 1<=p,q, r<=1,000,000.

Output

Print exactly one line for each test case. The line should contain one integer which is the smallest base for which p * q = r. If there is no such base, your program should output 0.

Sample Input

36 9 4211 11 1212 2 2

Sample Output

1330
题意:给你三个数字p,q,r,问在哪个最小的进制下p*q=r成立;

注意:假设在k进制下p,q,r的每位上的数字应该要小于k;

#include 
#include
using namespace std;int change(char *a,int k){ int len=strlen(a); int ans=0; for (int i=0;i
=k) return false; } return true;}int main(){ char a[10],b[10],r[10]; int t,i; cin>>t; while (t--){ cin>>a>>b>>r; for (i=2;i<=16;i++){ if (isBig(a,i)==true && isBig(b,i)==true && isBig(r,i)==true){ int aa = change(a,i); int bb = change(b,i); int rr = change(r,i); long long ans = aa*bb; long long ans2 = rr; if (ans==ans2) break; } } if (i==17) i=0; cout<
<

转载地址:http://shivx.baihongyu.com/

你可能感兴趣的文章
simhash进行文本查重 Simhash算法原理和网页查重应用
查看>>
python的异常机制使用技巧
查看>>
高速幂取余算法
查看>>
linux c获取mac
查看>>
Learning Lua Programming (2) Lua编程基础
查看>>
C# read weather xml
查看>>
全局变量如果不初始化,则默认为0,编译时编译器不提示“变量未初始化”。...
查看>>
HTML学记笔记
查看>>
CLR线程概览(一)
查看>>
cocos2dx游戏--欢欢英雄传说--添加血条
查看>>
WPF自定义控件(二)の重写原生控件样式模板
查看>>
【转】Flash:同志们,这些知识点你们知道多少?(一些必备的Flash开发知识点)...
查看>>
The N-dimensional array (ndarray)¶
查看>>
3. Spring Boot热部署【从零开始学Spring Boot】
查看>>
JpaSpecificationExecutor接口与自定义 Repository 方法&#x60;
查看>>
Java10来了,来看看它一同发布的全新JIT编译器
查看>>
今年双11,飞猪的“非OTA”之路走得怎么样了?
查看>>
苹果下架APP数量暴增超万款,看看你常用的在列吗?
查看>>
南非总统顾问一句想试试 马云当真了 做了件事你都想不到
查看>>
长虹软服常清雪:赋能数字化转型 看传统企业如何抢占先机
查看>>