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. Asp.net:MVC认识

    用MVC框架好长一段时间,发现每天都是写业务代码,不想每天只为了工作而写代码,想把工作中认识的MVC框架,遇到的问题,有时候天天在用,但是不知道里面是什么东西,什么原理,为啥這样写等一系列问题.进行梳 ...

  2. mysql中数据库的设计

      软件开发流程(CMMI): 1):项目启动; 2):项目计划: 3):需求分析; 需要得到的结果是什么? 4):系统设计;         该怎么做? 5):系统开发; 6):系统测试; 7):系 ...

  3. lua_protobuf

    http://www.cocoachina.com/bbs/read.php?tid-227404.html

  4. 文档声明和HTML样式表

    文档声明 不是注释也不是元素,总是在HTML的第一行 书写格式:<!DOCTYPE HTML> 是用于通知浏览器目前文档正使用哪一个HTML版本(相关属性 lang) 若不写文档声明,浏览 ...

  5. js数组的各种方法

    1.检测数组 ①Instanceof: if(value instanceof Array){ } 它假定只有一个全局执行环境,若网页中包含多个框架,则存在多个不同的全局执行环境,则Instanceo ...

  6. Android屏幕尺寸与度量单位(px,dp,sp)简介

    MarkdownPad Document *:first-child { margin-top: 0 !important; } body>*:last-child { margin-botto ...

  7. vi 命令学习(二)

    [选中文本(可视模式)] v 可视模式 从光标位置开始按正常模式选择文本 V 可视行模式 选中光标经过的完整行 ctrl + v 可视块模式 垂直方向选中文本 [ 撤销和恢复撤销] u undo 撤销 ...

  8. Leetcode724:寻找数组的中心索引(java、python3)

    寻找数组的中心索引 给定一个整数类型的数组 nums,请编写一个能够返回数组"中心索引"的方法. 我们是这样定义数组中心索引的:数组中心索引的左侧所有元素相加的和等于右侧所有元素相 ...

  9. 基于APE物理引擎的管线容积率计算方法

    容积率一般应用在房地产开发中,是指用地范围内地上总建筑面积与项目总用地面积的比值,这个参数是衡量建设用地使用强度的一项非常重要的指标.在其他行业,容积率的计算也非常重要,如产品利用率.管道使用率等等. ...

  10. relax 网站

    1. Calm 网站链接:http://www.calm.com/ 这个网站就像它的名字一样“平和”,网站的设计是通过自然图片(阳光下的暖流.流淌的消息等)与缓缓的音乐相结合,帮你在短时间内即可放松下 ...