LightOJ 1278 - Sum of Consecutive Integers 分解奇因子 + 思维
http://www.lightoj.com/volume_showproblem.php?problem=1278
题意:问一个数n能表示成几种连续整数相加的形式 如6=1+2+3,1种。
思路:先列式子\(N=a+(a+1)+(a+2)+ ...+(a+k-1)=\frac{k·(2a+k-1)}{2} \) 继续化成\(2a-1=\frac{2N}{k} - k \) 可由左式得知,2a-1必为奇数,那么右式必定是一奇一偶,且都为2N的因子。所以只要分解因子记录个数,最后组合求一下即可。
/** @Date : 2016-11-24-22.15
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version :
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
//#include<bits/stdc++.h>
#define LL long long
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e6+20;
int pri[670000];
int c = 0;
bool vis[N*10]; void prime()
{
MMF(vis);
for(int i = 2; i < N*10; i++)
{
if(!vis[i])
pri[c++] = i;
for(int j = 0; j < c && i * pri[j] < N*10; j++)
{
vis[i*pri[j]] = 1;
if(i % pri[j] == 0)
break;
}
}
} int main()
{
int T;
int cnt = 0;
cin >> T;
prime();
while(T--)
{
LL n;
scanf("%lld", &n);
LL ans = 1;
//while(n % 2 == 0)
// n/=2;
for(int i = 0; i < c && pri[i]*pri[i] <= n; i++)//记录素因子为奇数的(除2外的)
{
LL ct = 0;
while(n % pri[i] == 0)
{
if(i != 0)
ct++;
n /= pri[i];
}
ans *= (ct + 1);
}
if(n > 1 && n != 2)
{
ans *= 2;
}
printf("Case %d: %lld\n", ++cnt, ans-1);
}
return 0;
}
LightOJ 1278 - Sum of Consecutive Integers 分解奇因子 + 思维的更多相关文章
- LightOj 1278 - Sum of Consecutive Integers(求奇因子的个数)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1278 题意:给你一个数n(n<=10^14),然后问n能用几个连续的数表示; 例 ...
- Sum of Consecutive Integers
Sum of Consecutive Integers 题目链接 题意 问N能够分解成多少种不同的连续数的和. 思路 连续数是一个等差数列:$$ \frac{(2a1 + n -1)n}{2} = T ...
- Sum of Consecutive Integers LightOJ - 1278(推公式 数学思维)
原文地址:https://blog.csdn.net/qq_37632935/article/details/79465213 给你一个数n(n<=10^14),然后问n能用几个连续的数表示; ...
- poj 2379 Sum of Consecutive Prime Numbers
...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- ACM:POJ 2739 Sum of Consecutive Prime Numbers-素数打表-尺取法
POJ 2739 Sum of Consecutive Prime Numbers Time Limit:1000MS Memory Limit:65536KB 64bit IO Fo ...
- 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 ...
- Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers http://poj.org/problem?id=2739 Time Limit: 1000MS Memory Limit: 6 ...
随机推荐
- 基于angular+bower+glup的webapp
一:bower介绍 1:全局安装安装bower cnpm i -g bower bower常用指令: bower init //初始化文件 bower install bower uninstall ...
- php+原生ajax实现图片文件上传功能实例
html+js 代码 <!DOCTYPE html> <html> <head> <title>Html5 Ajax 上传文件</title> ...
- PHP 将一个字符串部分字符用$re替代隐藏
<?php/** * 将一个字符串部分字符用$re替代隐藏 * @param string $string 待处理的字符串 * @param int $start 规定在字符串的何处开始, * ...
- iOS开发本地通知
/* 本地通知:不通过网络,在本地实现的通知,自己发给自己 远程通知:必须通过网络,使用推送技术(APNs),实现通知 本地通知: 1.要完成可以接收的通知形式的注册 2.具体通知的设置 3.发送通知 ...
- 关于命令行参数argv(《学习OpenCV》)
在<学习OpenCV>这本书中,很多示例代码都用到了命令行参数.作为新手,之前总是很困扰,不知道怎么用.偶然的机会终于略知一二了. 在Visual Studio中,我们可以自行设置命令行参 ...
- 判断滚动条滚动到document底部
滚动条没有实际的高度.只是为了呈现效果才在外型上面有长度. 在js当中也没有提供滚动条的高度API. 参考了网上有关资料:判断滚动条到底部的基本逻辑是滚动条滚动的高度加上视口的高度,正好是docume ...
- PHP实现大文件分割上传与分片上传
转载:http://www.zixuephp.com/phpstudy/phpshilie/20170829_43029.html 服务端为什么不能直接传大文件?跟php.ini里面的几个配置有关 u ...
- Spring MVC之@RequestBody@ResponseBody详解
引言: 接上一篇文章讲述处理@RequestMapping的方法参数绑定之后,详细介绍下@RequestBody.@ResponseBody的具体用法和使用时机: 简介: @RequestBody 作 ...
- RT-thread 设备驱动组件之SPI设备
本文主要介绍RT-thread中的SPI设备驱动,涉及到的文件主要有:驱动框架文件(spi_dev.c,spi_core.c,spi.h),底层硬件驱动文件(spi_hard.c,spi_hard.h ...
- 优先队列实现 大小根堆 解决top k 问题
摘于:http://my.oschina.net/leejun2005/blog/135085 目录:[ - ] 1.认识 PriorityQueue 2.应用:求 Top K 大/小 的元素 3 ...