【杭电】[5747]Aaronson

文章字数:110

问题描述

问题分析

其实和那个问最少需用几张纸币付账的题目类似
由题意使$2^m$尽量大就好

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<stdio.h>
int main() {
    int T;
    scanf("%d",&T);
    while(T--) {
        __int64 n,m;
        scanf("%I64d %I64d",&n,&m);
        if(n==0) {
            printf("0\n");
            continue;
        }
        __int64 t=1,cnt=1;
        while(t<<1 <=n && cnt<=m) {
            cnt++;
            t<<=1;
        }
        __int64 sum=0;
        while(n) {
            sum+=n/t;
            n%=t;
            t>>=1;
        }
        printf("%I64d\n",sum);
    }
    return 0;
}

该内容采用 CC BY-NC-SA 4.0 许可协议。

如果对您有帮助或存在意见建议,欢迎在下方评论交流。

加载中...