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

3
6 9 42
11 11 121
2 2 2

Sample Output

13
3
0

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

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

#include <iostream>
#include <string.h>
using namespace std;
int change(char *a,int k){
int len=strlen(a);
int ans=0;
for (int i=0;i<len;i++){
ans = ans*k + a[i]-'0';
}
return ans;
}
bool isBig(char *a,int k){
int len=strlen(a);
for (int i=0;i<len;i++){
if (a[i]-'0'>=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<<i<<endl;
}
return 0;
}

poj 1331 Multiply的更多相关文章

  1. poj 1737 Connected Graph

    // poj 1737 Connected Graph // // 题目大意: // // 带标号的连通分量计数 // // 解题思路: // // 设f(n)为连通图的数量,g(n)为非连通图的数量 ...

  2. POJ 2389 Bull Math(水~Java -大数相乘)

    题目链接:http://poj.org/problem?id=2389 题目大意: 大数相乘. 解题思路: java BigInteger类解决 o.0 AC Code: import java.ma ...

  3. 瓶颈生成树与最小生成树 POJ 2395 Out of Hay

    百度百科:瓶颈生成树 瓶颈生成树 :无向图G的一颗瓶颈生成树是这样的一颗生成树,它最大的边权值在G的所有生成树中是最小的.瓶颈生成树的值为T中最大权值边的权. 无向图的最小生成树一定是瓶颈生成树,但瓶 ...

  4. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  5. POJ 1202 Family 概率,DP,高精 难度:2

    http://poj.org/problem?id=1202 难度集中在输出格式上,因为输出格式所以是高精度 递推式: 血缘肯定只有从双亲传到儿子的,所以,设f,m为双亲,son为儿子,p[i][j] ...

  6. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  7. Poj OpenJudge 百练 2389 Bull Math

    1.Link: http://poj.org/problem?id=2389 http://bailian.openjudge.cn/practice/2389/ 2.Content: Bull Ma ...

  8. poj 3710 Christmas Game(树上的删边游戏)

    Christmas Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1967   Accepted: 613 Des ...

  9. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

随机推荐

  1. 我要上google

    我要上google 一.下载google浏览器(百度下载) 二.获取和运行xx-net 1.https://github.com/XX-net/XX-Net 2.解压下载的xx-net,运行文件夹中的 ...

  2. JProfiler 9.1.1部署及使用

    软件准备: 官网下载地址:http://www.ej-technologies.com/download/jprofiler/files 软件部署: windows安装双击即可. 注册号: L-Lar ...

  3. C# 客户端读取共享目录文件

    控制台应用程序 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...

  4. Windows下压缩成tar.gz格式

    tar.gz 是linux和unix下面比较常用的格式,几个命令就可以把文件压缩打包成tar.gz格式,然而这种格式在windows并不多见,WinRAR.WinZip等主流压缩工具可以释放解开,却不 ...

  5. Gradle打包jar可执行程序

    1. 使用springboot插件 apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'spring-boot' buildscri ...

  6. MS-DOS Batch Script Template

    @echo off @setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION @rem Name: @rem Purpose: @rem @rem Autho ...

  7. CAD得到布局名

    js代码如下: var database = mxOcx.GetDatabase(); var sRet = null; //返回数据库中的布局字典 var spLayoutDictionary = ...

  8. 【转载】jxl的使用总结(java操作excel)

    jxl.jar是通过java操作excel表格的工具类库: 链接:https://pan.baidu.com/s/1AAT_eA_Q47zFeQohap6eQg 提取码:777b 1:通过模拟实现创建 ...

  9. Executors工厂类

    newCachedThreadPool 重用之前的线程 适合执行许多短期异步任务的程序. 调用 execute() 将重用以前构造的线程 如果没有可用的线程,则创建一个新线程并添加到池中 默认为60s ...

  10. HTML5 实现Link跳线效果

    之前我们推出过Flex版本的Link跳线效果,现在基于HTML5新版本的跳线效果也实现了,细微之处我们进行了改进,如link倾斜的时候Offset方向始终保持垂直等.先看效果.实现的算法和Flex基本 ...