当前位置:网站首页>All in one 1413: determine base
All in one 1413: determine base
2022-07-05 04:10:00 【Studying hard】
【 Title Description 】
6×9=42 It's wrong for the decimal system , But for 13 It's correct in hexadecimal . namely , 6(13)× 9(13)= 42(13), and 42(13)=4×131+2×130=54(10).
Your task is to write a program , Read in three integers p、q and r, Then determine a base B(2<=B<=40) bring p × q = r. If B There are many options , Output the smallest one .
for example :p=11, q=11, r=121. Then there are 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 hexadecimal 10, There are also 11(10)× 11(10)= 121(10). In this case , The output should be 3. If there is no suitable base , The output 0.
【 Input 】
a line , Contains three integers p、q、r. p、q、r All bits of are numbers , also 1 ≤ p、q、r ≤ 1,000,000.
【 Output 】
An integer : Even if have to p×q=r The smallest established B. If there is nothing suitable B, The output 0.
【 sample input 】
6 9 42【 sample output 】
13#include<stdio.h> #include<math.h> int getmin(int k,int j) { int temp; int i = 0; int count = 0; while (1) { temp = k % 10; count += temp * pow(j, i); i++; k /= 10; if (k == 0) { break; } } return count; } int main() { int m, n, k; scanf("%d%d%d", &m, &n, &k); int flag = 1; int num1, num2, num3; int j; for (j = 2; j <= 40; j++) { num1 = getmin(m, j); num2 = getmin(n, j); num3 = getmin(k, j); if (num1 * num2 == num3) { flag = 0; break; } } if (flag == 1) { printf("0"); } else { printf("%d", j); } return 0; }
边栏推荐
猜你喜欢

NEW:Devart dotConnect ADO. NET
![[phantom engine UE] only six steps are needed to realize the deployment of ue5 pixel stream and avoid detours! (the principles of 4.26 and 4.27 are similar)](/img/eb/a93630aff7545c6c3b71dcc9f5aa61.png)
[phantom engine UE] only six steps are needed to realize the deployment of ue5 pixel stream and avoid detours! (the principles of 4.26 and 4.27 are similar)

Looking back on 2021, looking forward to 2022 | a year between CSDN and me

@The problem of cross database query invalidation caused by transactional annotation

EasyCVR平台出现WebRTC协议视频播放不了是什么原因?

小程序中实现文章的关注功能

基于TCP的移动端IM即时通讯开发仍然需要心跳保活

Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘
![[phantom engine UE] realize the animation production of mapping tripod deployment](/img/89/351641c3da7e2acdbf389bc298b75e.png)
[phantom engine UE] realize the animation production of mapping tripod deployment

【虚幻引擎UE】运行和启动的区别,常见问题分析
随机推荐
[untitled]
Official announcement! The third cloud native programming challenge is officially launched!
Use Firefox browser to quickly pick up Web image materials
Learning notes 8
Convert Boolean to integer value PHP - Convert Boolean to integer value PHP
Three level linkage demo of uniapp uview u-picker components
An elegant program for Euclid‘s algorithm
Learning MVVM notes (1)
A应用唤醒B应该快速方法
UI automation test farewell to manual download of browser driver
UI自動化測試從此告別手動下載瀏覽器驅動
Enterprise level: spire Office for . NET:Platinum|7.7. x
面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?
Summary of scene design
Online sql to excel (xls/xlsx) tool
Why do big companies such as Baidu and Alibaba prefer to spend 25K to recruit fresh students rather than raise wages by 5K to retain old employees?
As soon as I write the code, President Wang talks with me about the pattern all day
我就一写代码的,王总整天和我谈格局...
长度为n的入栈顺序的可能出栈顺序
A application wakes up B should be a fast method