题意:求给出数的最小进制。
思路:暴力WA;
discuss中的idea:
给出数ABCD,若存在n 满足 (A* n^3 +B*n^2+C*n^1+D*n^0)%(n-1) == 0
则((A* n^3)%(n-1) +(B*n^2)%(n-1)+(C*n^1)%(n-1)+D%(n-1))%(n-1) == 0
(A+B+C+D)%(n-1) == 0
NB!
是时候深入的看下数论了;
#include <iostream> #include <algorithm> #include <stdlib.h> #include <time.h> #include <cmath> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <queue> #include <stack> #include <set> #define c_false ios_base::sync_with_stdio(false); cin.tie(0) #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3f #define zero_(x,y) memset(x , y , sizeof(x)) #define zero(x) memset(x , 0 , sizeof(x)) #define MAX(x) memset(x , 0x3f ,sizeof(x)) #define swa(x,y) {LL s;s=x;x=y;y=s;} using namespace std ; #define N 50005 const double PI = acos(-1.0); typedef long long LL ; int cal(char x){ if(x >= ‘0‘ && x <= ‘9‘) return x - ‘0‘; else if(x >= ‘A‘ && x <= ‘Z‘) return x - ‘A‘ +10; else if(x >= ‘a‘ && x <= ‘z‘) return x - ‘a‘ +36; return 0; } string s; int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); while(cin>>s){ int n = s.size(); int maxn = 0,sum = 0; for(int i = 0;i < n;i++){ sum +=cal(s[i]); maxn = max(maxn, cal(s[i])); } int flag = 1; for(int i = maxn+1; i <= 62; i++) if(sum%(i-1) == 0){ printf("%d\n",i); flag = 0; break; } if(flag) printf("such number is impossible!\n"); } return 0; }
时间: 2024-10-23 07:29:14