An Interesting Sequence

An Interesting Sequence

时间限制: 1000 ms  |  内存限制: 65535 KB
难度: 0
描述

YiYi is a smart boy, he is fascinated in solving eccentric problems. One day when he was reading a book, he came across a very interesting problem. After a few time’s thinking, he finally get the solution. YiYi considers this solution very heuristic, now he decides to show this problem to you so that you can also enjoy the happiness of solving this interesting problem. Here is the description of the problem:

Suppose at first you have a sequence, S1, consists of two numbers: 1, 1. According to some rule you can get the sequence Sn from the sequence Sn-1.Once you get Sn-1, you will be asked to insert one n between a and b if a and b are two adjacent numbers in Sn-1 and a + b = n. After you have inserted all possible n you finally get Sn. You can also get the sequence Sn+1 using the same method and so on. 

For example,S1 = 1,1.Since 1 + 1 = 2, we will insert 2 between two 1s and then we get S2, S2 = 1,2,1. Now we will insert two 3s in the sequence to get S3, as you can see, S3 = 1,3,2,3,1. In the same way, we know S4 = 1,4,3,2,3,4,1, S5 = 1,5,4,3,5,2,5,3,4,5,1 and so on.

Here the question comes: give you n, you will be asked to output the number of n in Sn. For example if n = 5, you will output 4 since there are 4 5s in S5.

输入
The first line of the input contains a number k, the number of test cases to solve (1 ≤ k ≤ 200). Each test case consists of a single integer 2 ≤ n ≤ 10^10 on a separate line.
输出
For each test case, you are asked to output the number of n in Sn on a line.
样例输入
3245
样例输出
124

import java.util.Scanner;

public class Main {

	public static long fun(long number) {
		long result = 1;
		for (long i = 2; i * i <= number; i++) {
			if (number % i == 0) {
				number /= i;
				result *= i - 1;
				while (number % i == 0) {
					number /= i;
					result *= i;
				}
			}
		}
		if (number > 1) {
			result *= number - 1;
		}
		return result;
	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int times = scanner.nextInt();
		while (times-- != 0) {
			long number = scanner.nextLong();
			System.out.println(fun(number));
		}
	}
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值