poj1152
简单题
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;
int value[300];
char st[1000000];
bool ok(int n)
{
int len = strlen(st);
for (int i = 0; i < len; i++)
if (value[st[i]] >= n)
return false;
int temp = 0;
int w = n - 1;
for (int i = 0; i < len; i++)
temp = (temp * n % w + value[st[i]] % w) % w;
return temp == 0;
}
int main()
{
//freopen("t.txt", "r", stdin);
for (char ch = '0'; ch <= '9'; ch++)
value[ch] = ch - '0';
for (char ch = 'A'; ch <= 'Z'; ch++)
value[ch] = ch - 'A' + 10;
for (char ch = 'a'; ch <= 'z'; ch++)
value[ch] = ch - 'a' + 36;
while (scanf("%s", st) != EOF)
{
int ans = -1;
for (int i = 2; i <= 62; i++)
if (ok(i))
{
ans = i;
break;
}
if (ans == -1)
printf("such number is impossible!\n");
else
printf("%d\n", ans);
}
return 0;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步