Spoj MMFLPDIV - Least prime divisor Solution

Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<iostream>
using namespace std;
int main()
{
    int n,i,f;
    while(cin>>n&&n!=0)
    {
        f=0;
        if(n==3)
            cout<<"3"<<endl;
        else
        {
            for(i=3; i*i<=n; i=i+2)
            {

                if(n%i==0)
                {
                    f=1;
                    break;
                }
            }
            if(f==1)
                cout<<i<<endl;
            else
                cout<<n<<endl;
        }

    }
}

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

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

Powered by Blogger.