CF 16C. Monitor

题目链接

水题依旧无法1Y。

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cmath>
 4 using namespace std ;
 5 #define LL __int64
 6 LL gcd(LL a,LL b)
 7 {
 8     return b == 0?a:gcd(b,a%b);
 9 }
10 
11 int main()
12 {
13     LL a,b,x,y,t;
14     LL str,end,mid;
15     scanf("%I64d%I64d%I64d%I64d",&a,&b,&x,&y);
16     t = gcd(x,y);
17     x = x/t;
18     y = y/t;
19     if(x > a||y > b)
20     {
21         printf("0 0\n");
22         return 0;
23     }
24     str = 1;
25     end = a/x;
26     while(str < end)
27     {
28         mid = (str+end + 1)/2;
29         if(mid*x > a||mid*y > b)
30         end = mid - 1;
31         else
32         str = mid;
33     }
34     printf("%I64d %I64d\n",end*x,end*y);
35     return 0;
36 }

posted @ 2013-10-19 12:28  Naix_x  阅读(173)  评论(0编辑  收藏  举报