csansoon

P2.21 X80452 Stamps

Sep 26th, 2018
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main() {
  6.    
  7.     int n;
  8.     while (cin >> n) {
  9.         int p = n/7, q = 0, pmin = 0, qmin = 0, min = n;
  10.         while (p >= 0) {
  11.             if ((7*p+4*(n-7*p)/4) == n) {
  12.                 q = (n-7*p)/4;
  13.                    
  14.              if (min > (p+q) and n == 7*p+4*q) {
  15.                  min = p + q;
  16.                  pmin = p;
  17.                  qmin = q;
  18.              }
  19.             }
  20.          --p;
  21.                  
  22.              
  23.         }
  24.          cout << pmin << " " << qmin << endl;
  25.      }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment