链接:
https://vjudge.net/problem/LightOJ-1336
题意:
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 σ.
思路:
考虑质数的约数和可以看作\((1+p_1^1+p_1^2+...+p_1^{k1})*(1+p_2^1+p_2^2+...+p_2^{k2})...\)
考虑和为奇数情况。
存在素因子2时,(1+2^n)为奇数,则和为奇数。
其他素因子为奇数,奇数乘奇数为奇数,1+偶数为奇数,偶数乘奇数为偶数,则只有素因子的指数为偶数时满足和为奇数。
由此得到其他数都为平方数。或者时平方数*2
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9;
const int MAXN = 1e6+10;
const int MOD = 1e9+7;
LL n;
int main()
{
int t, cnt = 0;
scanf("%d", &t);
while(t--)
{
printf("Case %d:", ++cnt);
scanf("%lld", &n);
LL tmp = n;
tmp -= (LL)sqrt(n);
tmp -= (LL)sqrt(n/2);
printf(" %lld\n", tmp);
}
return 0;
}
原文地址:https://www.cnblogs.com/YDDDD/p/11846273.html