Sigma Function (平方数与平方数*2的约数和是奇数)
Posted fighting-sh
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Sigma Function (平方数与平方数*2的约数和是奇数)相关的知识,希望对你有一定的参考价值。
Sigma Function
https://vjudge.net/contest/288520#problem/D
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 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define eb emplace_back 8 #define maxn 100005 9 #define eps 1e-8 10 #define pi acos(-1.0) 11 #define rep(k,i,j) for(int k=i;k<j;k++) 12 typedef long long ll; 13 typedef pair<int,int> pii; 14 typedef pair<long long,int>pli; 15 typedef pair<int,char> pic; 16 typedef pair<pair<int,string>,pii> ppp; 17 typedef unsigned long long ull; 18 const long long mod=998244353; 19 /*#ifndef ONLINE_JUDGE 20 freopen("1.txt","r",stdin); 21 #endif */ 22 23 int pow_mul(ll a,ll b){ 24 int ans=1; 25 while(b){ 26 if(b&1) ans=ans*a%1000; 27 b>>=1; 28 a=a*a%1000; 29 } 30 return ans; 31 } 32 33 int main(){ 34 #ifndef ONLINE_JUDGE 35 // freopen("1.txt","r",stdin); 36 #endif 37 // std::ios::sync_with_stdio(false); 38 int t; 39 cin>>t; 40 for(int _=1;_<=t;_++){ 41 ll n; 42 cin>>n; 43 int ans=0; 44 for(ll i=1;i*i<=n;i++){ 45 ans++; 46 if(i*i*2<=n) ans++; 47 } 48 cout<<"Case "<<_<<": "<<n-ans<<endl; 49 } 50 }
以上是关于Sigma Function (平方数与平方数*2的约数和是奇数)的主要内容,如果未能解决你的问题,请参考以下文章