Sum of Consecutive Integers

题目链接

题意

问N能够分解成多少种不同的连续数的和.

思路

连续数是一个等差数列:$$

\frac{(2a1 + n -1)n}{2} = T$$

那么\(\frac{2*T}{n}-n = 2*a1-1\),所以当\(n\)为\(T\)的奇因子的时候符合要求.

那么当\(n\)为偶数的时候\(\frac{2*T}{n}-(n-1) = 2*a1\);因为\((n-1)\)为奇数,\(2*a1\)为偶数,所以\(\frac{2T}{n}\)为奇数,所以另\(t\)上下含有的2的个数,必定上下含有2的个数必定相等,\(t = 2^t\)那么就得到\(\frac{\frac{2T}{t}}{\frac{n}{t}}\),那么另\(u = \frac{n}{t}\)那么\(u\)就是\(T\)的奇数因子,那么\(n = u*t\)就行了,因为每个\(n\)的值会一一对应一个连续的序列,所以即使当\(n\)为偶数的时候是通过求\(T\)的奇数因子而求得.所以通过求\(n\)为奇数时和\(n\)为偶数时,都是求T的奇数因子而求得,那么所有的种数就是求\(T\)的奇数因子的个数,除去1的时候。

然后就素数打表,\(T = p1^{k1} * p2^{k2}*p3^{k3}*...pn^{kn}\),那么如果\(T\)为偶数的话就把\(p\)为2的去掉,那么奇数因子个数就为\((k1+1)*(k2+1)*...(kn+1)\),最后再减个1就行了.

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
bool prime[10000005];
int table_prime[1000005];
int main(void)
{
for(int i = 2; i < 10000; i++)
{
if(!prime[i])
for(int j = i; (i*j) <= 10000000; j++)
prime[i*j] = true;
}
int cn = 0;
for(int i = 2; i <= 10000000; i++)
if(!prime[i])
table_prime[cn++] = i;
int T;
scanf("%d",&T);
int __cn = 0;
while(T--)
{
LL n;
scanf("%lld",&n);
int f = 1;
LL u = 0,sum = 1;
while(n%2 == 0)
n/=2;
while(n > 1&&f < cn)
{
if((LL)table_prime[f]*(LL)table_prime[f] > n)
break;
while(n%table_prime[f] == 0)
{
u++;
n/=table_prime[f];
}
sum = sum * (u+1);
u = 0;
f++;
}
if(n > 1)
sum *= (LL)2;
sum--;
printf("Case %d: ",++__cn);
printf("%lld\n",sum);
}
return 0;
}

Sum of Consecutive Integers的更多相关文章

  1. LightOj 1278 - Sum of Consecutive Integers(求奇因子的个数)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1278 题意:给你一个数n(n<=10^14),然后问n能用几个连续的数表示; 例 ...

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

    原文地址:https://blog.csdn.net/qq_37632935/article/details/79465213 给你一个数n(n<=10^14),然后问n能用几个连续的数表示; ...

  3. LightOJ 1278 - Sum of Consecutive Integers 分解奇因子 + 思维

    http://www.lightoj.com/volume_showproblem.php?problem=1278 题意:问一个数n能表示成几种连续整数相加的形式 如6=1+2+3,1种. 思路:先 ...

  4. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  5. POJ 2739 Sum of Consecutive Prime Numbers(尺取法)

    题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS     Memory Limit: 65536K Description S ...

  6. ACM:POJ 2739 Sum of Consecutive Prime Numbers-素数打表-尺取法

    POJ 2739 Sum of Consecutive Prime Numbers Time Limit:1000MS     Memory Limit:65536KB     64bit IO Fo ...

  7. POJ2739 Sum of Consecutive Prime Numbers 2017-05-31 09:33 47人阅读 评论(0) 收藏

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25225 ...

  8. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers http://poj.org/problem?id=2739 Time Limit: 1000MS   Memory Limit: 6 ...

  9. poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19697 ...

随机推荐

  1. C/C++ Qt StandardItemModel 数据模型应用

    QStandardItemModel 是标准的以项数据为单位的基于M/V模型的一种标准数据管理方式,Model/View 是Qt中的一种数据编排结构,其中Model代表模型,View代表视图,视图是显 ...

  2. 系列好文 | Kubernetes 弃用 Docker,我们该何去何从?

    作者 | 张攀(豫哲) 来源 | 尔达 Erda 公众号 导读:Erda 作为一站式云原生 PaaS 平台,现已面向广大开发者完成 70w+ 核心代码全部开源!**在 Erda 开源的同时,我们计划编 ...

  3. 零基础学习java------day8------javabean编写规范,继承,static关键字,代码块,单例设计模式

    0. 今日内容提要 1. javabean书写规范 javabean:一个普通的类,用来描述事物的类,里面不包含任何的业务逻辑,只是用来存储数据. 比如:Teacher,Student,Mobile. ...

  4. 淘宝、网易移动端 px 转换 rem 原理,Vue-cli 实现 px 转换 rem

       在过去的一段时间里面一直在使用Vue配合 lib-flexible和px2rem-loader配合做移动端的网页适配.秉着求知的思想,今天决定对他的原理进行分析.目前网上比较主流使用的就是淘宝方 ...

  5. 【leetcode】122.Best Time to Buy and Sell Stock II(股票问题)

    You are given an integer array prices where prices[i] is the price of a given stock on the ith day. ...

  6. clickhouse 输入输出格式

    TabSeparated.TabSeparatedRaw.TabSeparatedWithNames和TabSeparatedWithNamesAndTypes TabSeparated 默认格式,缩 ...

  7. GO类型转换

    golang []byte转string golang中,字符切片[]byte转换成string最简单的方式是 package main import ( "fmt" _ &quo ...

  8. 【Service】【Database】【MySQL】基础

    1. 概念 1.1. 作者:Unireg 1.2. MySQL AB --> MySQL Solaris:二进制版本: 1.3. 官方网站: MySQL: www.mysql.com Maria ...

  9. 基于Github Actions + Docker + Git 的devops方案实践教程

    目录 为什么需要Devops 如何实践Devops 版本控制工具(Git) 学习使用 配置环境 源代码仓库 一台配置好环境的云服务器 SSH远程登录 在服务器上安装docker docker技术准备工 ...

  10. 什么是API?

    一.简介 API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序,与开发人员基于某软件或硬件得以访问一组例程的能力,而又 ...