1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #include<iostream> #include<string> #include<cmath> using namespace std; int maxn,minn=1e9,x; int a[26];bool flag; int main(){ string s;cin>>s; int len=s.length(); for(int i=0;i<len;i++){ a[s[i]-'a']++; } for(int i=0;i<=25;i++) { if(a[i]!=0&&a[i]>maxn) { maxn=a[i]; } if(a[i]!=0&&a[i]<minn) { minn=a[i]; } } int ans=maxn-minn; if(ans==0||ans==1) { cout<<"No Answer"<<endl; cout<<0<<endl;return 0; } for(int i=2;i<=sqrt(ans);i++) { if(ans%i==0) { flag=1;break; } } if(flag==0) { cout<<"Lucky Word"<<endl; cout<<ans<<endl; } return 0; }
|