HDU 7100 Cut The Wire

Problem Description

In the country of Infinity , there is a strange road. This road only has a starting point, but no end. Since this road is infinite, there are also countless street lights. The street lights are numbered from 1(the starting point) to infinity. The street lights are connected by wires under a strange law:

For a street light x,




  •  
  • if x is even, then x is connected with x2 by a wire;


     
  • if x is odd, then x and 3x+1 is connected by a wire.

     



Now Kris is standing in the middle of street light n and n+1, and he is able to cut all wires passing by. That is, he will cut all wires connecting street lights a and b satisfying a≤n and b>n.

Now he wonders, how many wires he will cut. Please help him calculate.

 

Input

This problem contains multiple test cases.

The first line contains an integer T(1≤T≤105) indicating the number of test cases.

The next T lines each contains one integer n(1≤n≤109).

 

Output

For each test case, output one line of one integer indicating the answer.

 

Sample Input

 
 

2 12 60

 

Sample Output

 
 

10 50

题意:对于一个点x,如果编号为偶数那么x与x/2连通,如果为偶数那么x和3*x+1连通;给定一个编号n,克里斯站在n和n+1之间,同时斩断所有通过n和n+1的边,问将斩断多少边

思路:不论n是偶数还是奇数,总之n/2到n之间所有偶数点的边都将被切断,当n为奇数时,斩断的奇数边为(n-(n-1)/3)/2条,如果为偶数则为(n-(n-1)/3)/2条。

AC代码:

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

int n,m;

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n;
		int res=n-n/2;
		if(n%2)
			res+=(n-(n-1)/3+1)/2;
		else 
			res+=(n-(n-1)/3)/2;
		cout<<res<<endl;
	}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Double.Qing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值