Codeforces Beta Round #25 (Div. 2 Only) 25A - IQ test Solution
Problem Link : https://codeforces.com/problemset/problem/25/A
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n,i,a,f,j;
vector<long long>od,ev,pri,nopri;
cin>>n;
for(i=1; i<=n; i++)
{
f=0;
cin>>a;
if(a%2==0)
ev.push_back(i);
else
od.push_back(i);
for(j=2; j*j<=a; j++)
{
if(a%j==0)
{
f=1;
break;
}
}
if(f==1)
nopri.push_back(i);
else
pri.push_back(i);
}
if(ev.size()==1)
cout<<ev[0]<<endl;
else if(od.size()==1)
cout<<od[0]<<endl;
else if(nopri.size()==1)
cout<<nopri[0]<<endl;
else if(pri.size()==1)
cout<<pri[0]<<endl;
}
No comments