游客 Signup | Login
中文 | En

1670 - DotA

DotA(Defence of the Ancients) is very popular in Zhejiang University.Now a new hero appears in DotA.This hero has a miraculous skill.If the target's HP n is an even number,then it will be cut in half after skill-using.Otherwise the targe's HP will plus one after skill-using.Given a target's HP,we want to decrease the target's HP from n to 1 only with this new skill.

Input

The input consists of multiple test cases.Each case contain one line with an integer n(1<n≤1000000000).

Output

For each test case,output the target's HP's changing process on a single line.The HP values connect with '-' character.

Examples

Input

5
21

Output

5-6-3-4-2-1
21-22-11-12-6-3-4-2-1

Solution C

#include<stdio.h>
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d",n);
        while(1)
        {
            if(n%2==0)
            {
                printf("-%d",n/2);
                n=n/2;
            }
            else
              {
                      printf("-%d",n+1);
                      n=n+1;
              }
            if(n==1)
                break;
        }
        printf("\n");
    }
}

Solution C++

#include <stdio.h>
int n;
void run()
{
	printf("%d",n);
	while(n!=1)
	{
		if(n%2==1)
			n++;
		else
			n/=2;
		printf("-%d",n);//这道题唯一值得注意的地方就是不要输出多余的减号!!!每行里减号比数要少一个,所以注意判断。 
	}
	printf("\n");
}
int main()
{
	while(scanf("%d",&n)!=EOF)
		run();
	return 0;
} 
Time Limit 1 second
Memory Limit 32 MB
Discuss Stats
上一题 下一题