LightOJ1336 Sigma Function

题意

求和运算是一种有趣的操作,它来源于古希腊字母σ,现在我们来求一个数字的所有因子之和。例如σ(24)=1+2+3+4+6+8+12+24=60.对于小的数字求和是非常的简单,但是对于大数字求和就比较困难了。现在给你一个n,你需要求出有多少个数字的σ是偶数。
注:一个数字的σ指这个数的所有因子之和

Input

输入包含T(T<=100)组数据,每一组只有一个数字n(1<=n<=10^12)

Output

输出一个数字,为所求答案

Solution

转化思维,求一下是奇数的数
推一下发现,凡是奇数的完全平方数以及它的2^k幂都是
也就是完全平方数以及它的两倍的数都是

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(1e5 + 10), __(1e6 + 10);

IL ll Read(){
	char c = '%'; ll x = 0, z = 1;
	for(; c > '9' || c < '0'; c = getchar()) if(c == '-') z = -1;
	for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
	return x * z;
}

ll n, ans;

int main(RG int argc, RG char *argv[]){
	for(RG int T = Read(), i = 1; i <= T; ++i){
		n = Read(); ans = (ll)sqrt(1.0 * n) + (ll)sqrt(0.5 * n);
		printf("Case %d: %lld\n", i, n - ans);
	}
	return 0;
}



posted @ 2018-01-09 10:31  Cyhlnj  阅读(140)  评论(0编辑  收藏  举报