Editorial for Домашно


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.
by: maya

Тестовете можете да видите тук.

Примерно решение на C++:

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    long long n,i,p;
    if (n==1) {
      cout<<0<<endl;
    }
    else {
      cin>>n;
      i=2;
      p=0;
      while ( i<=sqrt(n)) {
        if (n%i==0)
        {
            p=i;
            break;
        }
        else i++;
     }
     if (i>sqrt(n))
       cout<<n-1<<endl;
     else 
      cout<<n-n/p<<endl;
    }
    return 0;
}

Comments

There are no comments at the moment.