首页 > 试题广场 >

HGCD

[编程题]HGCD
HH is learning GCD today, GCD is short for Greatest Common Divisor.  You can look at this implementation:
long long gcd(long long a, long long b){
	while(a > 0 && b > 0){
	    a %= b;
	    swap(a , b);
	}
	return a + b;
}
But HH is so careless that he changes "%" into "-", let's call this new funtion HH′s Greatest Common Divisor (HGCD). You can look at this implementation:

long long hgcd(long long a, long long b) {
    while (a > 0 && b > 0) {
        a -= b;
        swap(a , b);
    }
    return a + b;
}
Now HH run HGCD(a,b) for all 1≤a≤n, 1≤b≤n,HH wants to know how many times does his algorithm - HGCD works correctly. 

Note:

void swap(long long &a, long long &b){
    long long t = a;
    a = b; b = t;
}


输入描述:
The first line of input will contain an integer T(1≤T≤5),denoting the number of test cases.  For each test case: The first and only line contains an integer n (1≤n≤1012)


输出描述:
For every test case output the number of times gcd(a,b)==hgcd(a,b) It's guaranteed that long long is enough for this problem.
示例1

输入

2
3
2

输出

8
4

说明

In the first example, we have gcd(a,b)==hgcd(a,b) for all 1≤a≤3,1≤b≤3 except a=2,b=3)

这道题你会答吗?花几分钟告诉大家答案吧!

问题信息

上传者:牛客301599号
难度:
0条回答 1791浏览

热门推荐

通过挑战的用户