FZU-2268 Cutting Game

本文介绍了一种特殊的金币切割游戏,玩家需要将整块金币切割成若干份以便于购买不同长度的商品而无需找零。文章提供了算法解决方案,通过不断除以2的方法来确定最少切割次数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                                       点击打开链接Problem 2268 Cutting Game

Accept: 219    Submit: 525
Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

Fat brother and Maze are playing a kind of special (hentai) game with a piece of gold of length N where N is an integer. Although, Fat Brother and Maze can buy almost everything in this world (except love) with this gold, but they still think that is not convenient enough. Just like if they would like to buy the moon with M lengths of the gold, the man who sold the moon need to pay back Fat Brother and Maze N-M lengths of the gold, they hope that they could buy everything they can afford without any change. So they decide to cut this gold into pieces. Now Fat Brother and Maze would like to know the number of the pieces they need to cut in order to make them fulfill the requirement. The number of the gold pieces should be as small as possible. The length of each piece of the gold should be an integer after cutting.

Input

The first line of the data is an integer T (1 <= T <= 100), which is the number of the text cases.

Then T cases follow, each case contains an integer N (1 <= N <= 10^9) indicated the length of the gold.

Output

For each case, output the case number first, and then output the number of the gold pieces they need to cut.

Sample Input

13

Sample Output

Case 1: 2

Hint

In the first case, the gold can be cut into 2 pieces with length 1 and 2 in order to buy everything they can afford without change.

PS:刚开始一直摸不着头脑,后来列了几项,渐渐才找到了规律。

AC:

#include<stdio.h>

int main()
{
int t,n,i,m;
scanf("%d",&t);
i=1;
while(t--)
{
scanf("%d",&n);
m=1;
while(n>1)
{
n/=2;
m++;
}
printf("Case %d: %d\n",i++,m);
}
return 0;
}               

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值