• <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 閱讀(517) 評論(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
            热RE99久久精品国产66热| AV色综合久久天堂AV色综合在| 国产一区二区精品久久| 大美女久久久久久j久久| 久久亚洲国产最新网站| 狠狠88综合久久久久综合网| 99国内精品久久久久久久| 久久久久亚洲AV片无码下载蜜桃| 精品久久无码中文字幕| 一本色道久久综合| 久久综合九色综合久99| 亚洲精品乱码久久久久66| 国产精品内射久久久久欢欢| 久久中文字幕人妻熟av女| 久久91精品久久91综合| 久久久久亚洲AV成人网人人网站| www亚洲欲色成人久久精品| 久久婷婷成人综合色综合| 一本大道久久东京热无码AV| 久久久免费精品re6| 久久久精品国产免大香伊| 国产精品久久久久乳精品爆| 国产成人精品白浆久久69| 久久青青草原精品国产软件 | 青青草原综合久久| 精品久久亚洲中文无码| 久久亚洲AV无码西西人体| 91秦先生久久久久久久| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 色婷婷狠狠久久综合五月| 亚洲精品国产成人99久久| 欧美亚洲国产精品久久蜜芽| 日本三级久久网| 91精品国产色综久久| 一级做a爰片久久毛片人呢| 狠狠色婷婷综合天天久久丁香| 91精品国产色综合久久| 蜜桃麻豆www久久| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区| 久久久久国产精品人妻| 色婷婷综合久久久久中文|