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 ...
随机推荐
- location 匹配规则 (NGINX)
转:https://moonbingbing.gitbooks.io/openresty-best-practices/ngx/nginx_local_pcre.html location 匹配规则 ...
- 在Excel里面,单元格里输入公式后只显示公式本身,不显示结果,怎么办
这种情况是对Excel进行了设置,设置的就是在单元格中只显示公式,不显示结果,解决的办法有两个: 1 用快捷键CTR+~ 2 点击"公式"选项卡,然后反选里面的"显示公式 ...
- 王者荣耀交流协会beta冲刺贡献分分配结果
根据原来约定的(贡献分分配规则){http://www.cnblogs.com/gaoyb348/p/7828523.html} 总共20个任务,一共35分,那么一个任务1.75分. 冉华完成了9个任 ...
- WEB安全测试要点总结
一.大类检查点: 二.测试项详细说明 上传功能 绕过文件上传检查功能 上传文件大小和次数限制 注册功能 注册请求是否安全传输 注册时密码复杂度是否后台校验 激活链接测试 重复注册 批量注册问题 登录 ...
- dedecms添加新模型
dedecms虽然预设了一些常见网页的功能模型,但是如果需要新的功能则需要自己创建,dedecms也提供了创建新模型的功能,如下: 1.打开后台首页=>核心=>内容模型管理 2.添加新模型 ...
- SIM卡是什么意思?你所不知道的SIM卡知识扫盲(详解)【转】
原文链接:http://www.jb51.net/shouji/359262.html 日常我们使用手机,SIM卡是手机的必须,没有了它就不能接入网络运营商进行通信服务.SIM卡作为网络运营商对于我们 ...
- mysql突然无法启动的问题
经常会有这样一个情况是:mysql跑了一段时间后,某一天我们需要重启服务的时候,发现停止后并不能正常启动,会报下面这种错误 这种情况发生的原因绝大多数都是权限的问题: 因为使用了一段时间后,使用期间表 ...
- Lucene笔记二
lucene 的排序 package cn.itcast.lucene; import java.io.IOException; import org.apache.lucene.document.D ...
- android应用打前需要准备些啥?
发布之前我们需要准备的东西 参考了google官方和结合国内开发经验 1) 用户协议(本地.网络.API) 2) 签名文件(用于为APP加密,唯一标签) 3) 程序图标(第一个面对用户,准备不同的但合 ...
- P3074 [USACO13FEB]牛奶调度Milk Scheduling
题目描述 Farmer John's N cows (1 <= N <= 10,000) are conveniently numbered 1..N. Each cow i takes ...