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

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.