51nod 1116 K进制下的大数

    xiaoxiao2021-03-25  92

    想到k%(k-1)=1

    k^n%(k-1)=1

    所以 这个大数取膜k-1的值就是等于 各个位置数的和  比如 A1A%(k-1)=(A+1+A)=(10+1+10)%(k-1)=0

    所以我们只需要 求出各个位子的和之后枚举k-1就可以了

    #include<cstdio> #include<cstring> #include<iostream> #include<math.h> #include<algorithm> #include<queue> using namespace std; #define MX 111111 #define INF 0x3f3f3f3f3f3f3f3f #define mem(x,y) memset(x,y,sizeof(x)) typedef long long LL; string s; int getnum(char c) { if(c>='0'&&c<='9') return c-'0'; return 10+c-'A'; } int main() { freopen("input.txt","r",stdin); while(cin>>s) { int cnt=0,maxn=0; for(int i=0; i<s.size(); i++) { int t=getnum(s[i]); maxn=max(maxn,t); cnt+=t; } int ans=-1; for(int i=maxn; i<=35; i++) if(cnt%i==0) { ans=i; break; } if(ans==-1) printf("No Solution\n"); else printf("%d\n",ans+1); } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-24516.html

    最新回复(0)