• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            我希望你是我獨家記憶

            一段永遠封存的記憶,隨風而去
            posts - 263, comments - 31, trackbacks - 0, articles - 3
               :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

            SGU126

            Posted on 2010-12-03 15:23 Hero 閱讀(524) 評論(0)  編輯 收藏 引用 所屬分類: 代碼如詩--ACM
             1 //SGU 126  .CPP_VS Accepted 22 ms 0 kb 
             2
             3/*
             4126. Boxes 
             5
             6time limit per test: 0.50 sec. 
             7memory limit per test: 4096 KB 
             8
             9
            10There are two boxes. There are A balls in the first box, and B balls in the second box (0 < A + B < 2147483648). It is possible to move balls from one box to another. From one box into another one should move as many balls as the other box already contains. You have to determine, whether it is possible to move all balls into one box. 
            11
            12
            13Input
            14
            15The first line contains two integers A and B, delimited by space. 
            16
            17
            18Output
            19
            20First line should contain the number N - the number of moves which are required to move all balls into one box, or -1 if it is impossible. 
            21
            22
            23Sample Input
            24
            25Sample Output
            26
            272 6
            28
            29
            30Sample Output
            31
            322
            33*/

            34
            35//如果log(2, (a+b)/gcd(a, b))是整數,那么它就是答案;否則無解.
            36
            37#include <iostream>
            38#include <string>
            39#include <set>
            40using namespace std;
            41typedef __int64 llong;
            42int answer;
            43
            44llong fgcd( llong a, llong b )
            45{
            46    if0 == a ) return b;
            47    else
            48        return fgcd( b%a, a );
            49}

            50
            51int main()
            52{
            53#ifdef _ACM_
            54    //freopen( "data.in", "r", stdin ) ;
            55    //freopen( "data.out", "w", stdout ) ;
            56#endif
            57    llong ina, inb;
            58    
            59    while( cin >> ina >> inb )
            60    {
            61        answer = -1 ;
            62
            63        if( ina < 0 || inb < 0 )
            64        {
            65            answer = -1;
            66        }

            67        else if( ina == 0 || inb == 0 )
            68        {
            69            answer = 0;
            70        }

            71        else
            72        {
            73            llong gcdvalue = fgcd(ina, inb);
            74            ina = ina / gcdvalue;
            75            inb = inb / gcdvalue;
            76
            77            llong sum = ina + inb;
            78            forint i=1; i<60; i++ )
            79            {
            80                llong pow2 = 1 << i;
            81                if( pow2 == sum )
            82                {
            83                    answer = i; break;
            84                }

            85                else if( pow2 > sum )
            86                {
            87                    break;
            88                }

            89            }

            90        }

            91
            92        printf( "%d\n", answer );
            93    }

            94
            95    return 0;
            96}

            97
            久久久久18| 久久精品国产精品亚洲艾草网美妙| 日产久久强奸免费的看| 亚洲国产成人乱码精品女人久久久不卡| 香港aa三级久久三级老师2021国产三级精品三级在 | 99精品久久久久中文字幕| 久久国产亚洲精品| 久久综合香蕉国产蜜臀AV| 色欲综合久久躁天天躁蜜桃| 国产精品国色综合久久| 国产综合免费精品久久久| 久久天天躁狠狠躁夜夜2020一| 欧美黑人激情性久久| 久久久无码精品午夜| 久久夜色精品国产欧美乱| 久久99亚洲综合精品首页| 久久天天躁狠狠躁夜夜avapp| 久久久久亚洲av毛片大| 久久国产精品久久久| 精品国产青草久久久久福利| 久久99精品久久久久久噜噜| 久久一日本道色综合久久| 99久久国产综合精品女同图片| 91亚洲国产成人久久精品| 久久人人爽人人爽人人片av高请| 国产免费久久精品99久久| 97久久超碰国产精品旧版| 97久久国产露脸精品国产| 日本久久中文字幕| 日本加勒比久久精品| 久久亚洲精品无码观看不卡| 99久久精品无码一区二区毛片 | 久久青青草原亚洲av无码| 久久99精品国产自在现线小黄鸭 | 久久国产免费直播| 亚洲精品无码久久不卡| 国产激情久久久久影院老熟女| 久久久精品2019免费观看| 久久国产免费观看精品3| 亚洲va久久久噜噜噜久久| 成人久久免费网站|