You are provided an integer n. Your task is to determine the largest integer a (a<n1) that is a coprime of ngiven number.


Solution

#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int num;
cin >> num;
for(int i=num-2;i>0;i--)
   {
     if( __gcd(num,i)==1)
      {
          cout<<i;
          break;
       }
    } 
}


if you have any problem in this code, take a screen shot and contact with Rishabh Chaubey.

Post a Comment

Previous Post Next Post