Sigma Function

来源:互联网 发布:域名怎么绑定自己电脑 编辑:程序博客网 时间:2024/05/07 13:17

Sigma function is an interesting function in Number Theory. It is denoted by the Greek letter Sigma (σ). This function actually denotes the sum of all divisors of a number. For example σ(24) = 1+2+3+4+6+8+12+24=60. Sigma of small numbers is easy to find but for large numbers it is very difficult to find in a straight forward way. But mathematicians have discovered a formula to find sigma. If the prime power decomposition of an integer is

Then we can write,

For some n the value of σ(n) is odd and for others it is even. Given a value n, you will have to find how many integers from 1 to n have even value of σ.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 1012).

Output

For each case, print the case number and the result.

Sample Input

4

3

10

100

1000

Sample Output

Case 1: 1

Case 2: 5

Case 3: 83

Case 4: 947

题目大意:求1到n之间的数因子和是偶数有几个对于任意一个x, 都有x = p1^a1*p2^a2*...*pn^an;所以x的因子和 f(x)= (1+p1+p1^2+p1^3+...+p1^a1)*(1+p2+p2^2+...+p2^a2)*...*(1+pn+pn^2+...+pn^an);因为偶数乘偶数是偶数,偶数乘奇数还是偶数,只有奇数乘奇数是奇数,所以我们必须让每一个小括号都是奇数。最后我们减去奇数项就只剩偶数项了1,然后我们发现当x只有2这一个素因子时,再加上一个1一定是奇数。2, 素数中只有2一个偶数,所以其他素数都是奇数,偶数个奇数想加就是偶数,再加一个1就又会变成偶数,所以p^a(a必须是偶数)x^2的每一个p^a(a一定会是偶数,因为是两个x相乘,所以就是两个a相加,不管是奇数加奇数,还是偶数加偶数都会是偶数)3,x^2因子和是偶数了,那么2*x^2的因子和也一定是偶数。因为就算再多一个2也没关系,最后还是会加上一个1还是奇数。所以最后只用减去2^x,x^2和2*x^2,x^2和2*x^2又包含2^x,所用只用减去x^2和2*x^2.

#include<stdio.h>#include<iostream>#include<math.h>#include<string.h>#include<algorithm>using namespace std;#define ll long longint main(){    int t;    scanf("%d",&t);    int g=0;    while(t--)    {        ++g;        ll n;        scanf("%lld",&n);        ll sum=n;        sum-=(int)sqrt(n);        sum-=(int)sqrt(n/2);        printf("Case %d: %lld\n",g,sum);    }}


0 0
原创粉丝点击