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 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 &g...

Powered by Blogger.