FZU2268 Cutting Game (mathematics, Law) (Seventh Fujian University student Program Design Competition)

Source: Internet
Author: User
Tags time limit

Topic:

problem 2268 Cutting Game accept:10 Submit:12
Time limit:1000 mSec Memory limit:32768 KB
problem Description

Fat brother and Maze is playing a kind of the special (hentai) game with a piece of gold of length n where n was an integer. Although, Fat Brother and Maze can buy almost everything in this world (except love) with this gold, but they still think That's 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 Br Other 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 RE Quirement. The number of the gold pieces should be as small as possible. The length of each piece of the gold should is an integer after cutting. Input

The first line of the data is a integer T (1 <= t <=), 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 sample Output case 1:2 Hint

In the first case, the gold can is cut into 2 pieces with length 1 and 2 in order to buy everything they can afford Withou T change. Source Seventh Fujian University student Program design contest-Replay (thanks to the Fang College) ideas:

Give you a number, and then let you cut, ask is the least cut a few, you can compose all the numbers

This is a rule, which is actually to ask for the number of binary numbers


Code:

#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
# Include <set>
#include <iostream>
#include <stack>
#include <cmath>
# Include <queue>
#include <vector>
#include <algorithm>
#define MEM (A, B) memset (A, B, sizeof (a))
#define INF 0x3f3f3f3f
#define MOD 1000007
#define N 20200
#define M 12357
#define ll long long
using namespace std;
int main ()
{
	int t,n,q=1;
	scanf ("%d", &t);
	while (t--)
	{
		scanf ("%d", &n);
		int sum=0;
		while (n!=0)
		{
			sum++;
			n/=2;
		}
		printf ("Case%d:%d\n", q++,sum);
	}
	return 0;
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.