(进制转化)
来源:互联网 发布:python exe反编译工具 编辑:程序博客网 时间:2024/06/01 20:31
A few days earlier a certain mathematician had been fired from his job so he has made up his mind to take revenge on his former employers and has changed all the numbers in their databases to their corresponding forms in different numerical systems using different bases. At the beginning it seemed to everyone to be just a stupid joke and hopefully they would soon find the correct data hidden somewhere.They were wrong, because even the backup database copies have been changed. The only hint, they were given was that all the data had been transformed to systems with such a base that it is the smallest base in which input numbers are squares.
Your task is to find these bases. You need to hurry up, because the whole firm’s activity depends on your database fix. You may however assume that:
• for each number, there exists a sought base and it is less than 100
• all the digits in input numbers are characters 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
• each number written in decimal system is smaller that 1000000000
Input
Data set consists of lines containing single numbers. Occurrence of ‘0’ means the end of data set (0 is not treated as valid data).
Output
For each number you should find a smallest base of a numerical system in which this number is a square of some other number. Each number should be outputted in separate line.
Sample Input
61
1100
509
510
1013
0
Sample Output
8
3
12
16
6
给出一个数,问这个数在哪个进制下会是一个完全平方数,我们可以枚举它的进制后将他转化到10进制下判断他是否为完全平方数。
代码:
#include<iostream>#include<string>#include<cstdio>#include<algorithm>#include<cmath>#include<iomanip>#include<queue>#include<cstring>#include<map>using namespace std;typedef long long ll;#define M 55char str[500];int len;ll solve(ll x) //假设其为x进制,并转化为10进制{ ll ans=str[0]-'0'; for(int i=1;i<len;i++) { ans=ans*x+str[i]-'0'; } return ans;}int main(){ int i,maxv; ll temp; while(scanf("%s",str)!=EOF) { len=strlen(str); if(len==1&&str[0]=='0') break; maxv=-1; for(i=0;i<len;i++) { maxv=max(maxv,str[i]-'0'); } for(i=maxv+1;i<=100;i++) //这个数至少为maxv+1进制 { temp=solve(i); ll t=(ll)sqrt(1.0*temp); if((t*t)==temp) { printf("%d\n",i); break; } } } return 0;}
- (进制转化)
- 进制转化(常用的简单转化)
- 进制转化(高到低)
- 进制转化(10->2)
- 进制转化(C++完整版)
- NUMBER BASE CONVERSION(进制转化)
- 进制转化(栈应用)
- 进制转化(尤其是负进制)
- 进制转化(16->10)
- hdu 4799 进制转化(水)
- 进制转化(小bug)
- 进制转化
- 进制转化
- 进制转化
- 进制转化
- 进制转化
- 进制转化
- java进制转化
- 20171112
- 6.18
- 梯度方向直方图(HOG)
- 泛型
- 软件工程(C编码实践篇)学习总结
- (进制转化)
- 徐登沿的第五个程序(单精度实型和双精度实型的有效位数)
- XRecycleView的一系列事件
- 使用Eclipse的几个必须掌握的快捷方式
- C# MVC的一种高效分页的html方法
- 集成学习
- 手把手实现JSP +SQLServer2012实现站点界面成绩查询
- python高级技能
- 输出一个整数序列中与指定数字相同的数的个数