Thursday, 14 September 2017

Codeforce Problem 854A - Fraction Solution (C++)

Problem:

Please find the problem 
here.

Solution:

This is the simplest problem I ever had, just implement the given formulas! However, it does take me some time to write.

Code:




#include <bits/stdc++.h>

using namespace std;
int main(){
int n,sum;
cin>> n;
for(int i=n/2;i>=1;i--){
    if(__gcd(i,n-i)== 1){

        cout<<i<< " "<<n-i<<endl;
return 0;
    }

}

}






No comments:

Post a Comment

Spoj Problem ACMCEG2C - Pick the candies (C++)

  The problem link may be found here.       Explanation: Use Deque to keep track of elements of the variety of candies. If i is gre...