Arjit challenges Deepa that if she can divide the weight of the cake as sum of two prime numbers between them, she can have the entire cake - and if she fails to do so, he'll get the cake.
Explanation
#include<iostream.h>
4 can be represented as 2 + 2, so Deepa wins.
8 can be represented as 5 + 3, so Deepa wins.
8 can be represented as 5 + 3, so Deepa wins.
int prime(int n){
int a=1;
for(int j=2;j<=n/2;++j)
if(n%j==0){
--a;
break;
}
return a;
}
int main()
{
int t, n ,p2 ,f=0;
cin>>t;
while(t--)
{
cin>>n;
for(int i=2;i<n;++i)
if(prime(i))
{
p2=n-i;
if(prime(p2)){
f=1;
break;
}
}
if(f==1){
cout<<"Deepa\n";
--f;
}
else cout<<"Arjit\n";
}
}
No comments:
Post a Comment