Your task is to calculate sum of primes present as digits of given number N.
Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The next T lines contains an integer N.
Output:
Print sum of primes in the digit
Constraints:
1 ≤ T ≤ 50
2 ≤ N ≤ 50000
Output:
Print sum of primes in the digit
Constraints:
1 ≤ T ≤ 50
2 ≤ N ≤ 50000
Example:
Input:
2
333
686
333
686
Output:
9
0
9
0
Your Code
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int sum=0;
while(n!=0)
{
int x;
x=n%10;
n=n/10;
int i,temp=1;
for(i=2; i<=x/2; i++)
{
if(x%i==0)
{
temp=0;
break;
}
}
if(temp==1 && x!=1)
{
sum=sum+x;
}
}
cout<<sum<<endl;
}
}