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

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.