• <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 閱讀(526) 評論(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
            国产叼嘿久久精品久久| 91精品国产91久久久久久蜜臀| 一本一本久久A久久综合精品 | 99久久做夜夜爱天天做精品| 色婷婷久久综合中文久久蜜桃av| 久久97久久97精品免视看| 日韩精品久久久肉伦网站| 精品久久久久久无码中文字幕一区| 青青草原综合久久大伊人导航 | 久久亚洲精品人成综合网| 久久香蕉综合色一综合色88| 中文字幕久久精品无码| 狠狠色丁香久久婷婷综合五月| 久久99精品久久久久久水蜜桃| 97精品依人久久久大香线蕉97| 999久久久免费国产精品播放| 久久精品国产清自在天天线| 2021最新久久久视精品爱| 国产午夜福利精品久久2021| 人人狠狠综合久久亚洲| 久久精品亚洲中文字幕无码麻豆| 伊人久久大香线焦AV综合影院 | 欧美日韩久久中文字幕| 香蕉久久夜色精品国产小说| 亚洲AV无码久久精品蜜桃| 国产亚洲精久久久久久无码77777| 日本道色综合久久影院| 久久久久成人精品无码中文字幕| 久久久久久极精品久久久 | 99久久精品国产一区二区蜜芽| 性做久久久久久久| 日韩一区二区三区视频久久| 久久久久国产视频电影| 国产99久久久久久免费看| 久久久国产精品网站| 久久91精品国产91久久户| 久久国产精品免费| 久久亚洲精品视频| 久久亚洲国产欧洲精品一| 免费观看成人久久网免费观看| 日韩亚洲欧美久久久www综合网|