Advertisement
tautas

Untitled

Apr 5th, 2017
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <stdbool.h>
  4. double min(double a, double b)
  5. {
  6.     if(a<b)
  7.         return a;
  8.     return b;
  9. }
  10. int main()
  11. {
  12.     long a, h, w;
  13.     scanf("%d",&a);
  14.     scanf("%d",&h);
  15.     scanf("%d",&w);
  16.     double x = 10000000000;
  17.     bool t = false;
  18.     for (int k = 1; k * a <= h; k++)
  19.     {
  20.         long l = ( a * k + k * w + w - h) / (a + h);
  21.         if (l>=0 && (h - a * k) * (l + 1) == (w - a * l) * (k + 1))
  22.         {
  23.             t = true;
  24.             x = min(x, ((double)(h - a * k)) / ((double)(k + 1)));
  25.         }
  26.     }
  27.     if (t)
  28.         printf("%f",x);
  29.     else
  30.         printf("-1");
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement