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;
}
}