| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
傻了,如此简单#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <stack>
#include <string.h>
#include <vector>
using namespace std;
char buf[300000];
int ToInt(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
} else if (c >= 'A' && c <= 'Z') {
return c - 'A' + 10;
} else {
return c - 'a' + 36;
}
}
int main() {
while (scanf("%s", buf) != EOF) {
int min_base = 2;
long len = strlen(buf);
for (long i = 0; i < len; ++i) {
if (ToInt(buf[i]) + 1 > min_base) {
min_base = ToInt(buf[i]) + 1;
}
}
bool flag = false;
for (int base = min_base; base <= 62; ++base) {
int cur = 0;
for (int i = -1; i < len - 1; ++i) {
cur = (cur % (base - 1)) * base + ToInt(buf[i + 1]);
}
if (cur % (base - 1) == 0) {
printf("%d\n", base);
flag = true;
break;
}
}
if (flag == false) {
printf("such number is impossible!\n");
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator