Sum of Consecutive Integers LightOJ - 1278(推公式 数学思维)

原文地址:https://blog.csdn.net/qq_37632935/article/details/79465213

求出sum奇因子的个数 就是答案  用算术基本定理的代码求就好了  vis设置为bool的 要不会翻车。。 答案要减一 因为1不是奇数

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(a, n) for(int i=1; i<=n; i++)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 10000000, INF = 0x7fffffff;
int primes[1000000];
bool vis[maxn];
int ans = 0;
void init()
{
    mem(vis, 0);
    for(int i=2; i<maxn; i++)
    {
        if(vis[i]) continue;
        primes[ans++] = i;
        for(LL j=(LL)i*i; j<maxn; j+=i)
            vis[j] = 1;
    }
}


int main()
{
    init();
    int T, kase = 0;
    cin>> T;
    while(T--)
    {
        LL n, res = 1;
        cin>> n;
        for(int i=0; i<ans && primes[i]*primes[i] <= n; i++)
        {
            LL cnt2 = 0;
            while(n % primes[i] == 0)
            {
                n /= primes[i];
                cnt2++;
            }
            if(cnt2 > 0 && primes[i] % 2)
                res *= (cnt2 + 1);
        }
        if(n > 1 && n % 2)
        {
            res *= 2;
        }
        printf("Case %d: %lld\n", ++kase, res - 1);


    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/WTSRUVF/p/9350470.html