problem link::
https://uva.onlinejudge.org/external/109/10924.pdf
solution::
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
while(cin>>str)
{
long long int c=0,sum=0;
for(int i=0;i<str.size();i++)
{
if(islower(str[i]))
{
sum+=(str[i]-'a')+1;
}
else
{
sum+=(str[i]-'A')+27;
}
}
for(int j=2;j<=sqrt(sum);j++)
{
if(sum%j==0)
{
c=1;
break;
}
}
if(c==1)
{
cout<<"It is not a prime word."<<endl;
}
else
{
cout<<"It is a prime word."<<endl;
}
}
return 0;
}
No comments:
Post a Comment