zoukankan      html  css  js  c++  java
  • Sum of Consecutive Integers LightOJ

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

    给你一个数n(n<=10^14),然后问n能用几个连续的数表示;

    求出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
    ", ++kase, res - 1);
    
    
        }
    
        return 0;
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    服务部署 RPC vs RESTful
    模拟浏览器之从 Selenium 到splinter
    windows程序设计 vs2012 新建win32项目
    ubuntu python 安装numpy,scipy.pandas.....
    vmvare 将主机的文件复制到虚拟机系统中 安装WMware tools
    ubuntu 修改root密码
    python 定义类 简单使用
    python 定义函数 两个文件调用函数
    python 定义函数 调用函数
    python windows 安装gensim
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9350470.html
Copyright © 2011-2022 走看看