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 ... 
随机推荐
- 最小生成树(Kruskal和Prim算法)
			关于图的几个概念定义: 关于图的几个概念定义: 连通图:在无向图中,若任意两个顶点vi与vj都有路径相通,则称该无向图为连通图. 强连通图:在有向图中,若任意两个顶点vi与vj都有路 ... 
- do_try_to_free_pages
			/* * This is the main entry point to direct page reclaim. * * If a full scan of the inactive list fa ... 
- change object keys & UpperCase & LowerCase
			change object keys & UpperCase & LowerCase .toLocaleUpperCase(); && .toLocaleLowerCa ... 
- 第51天:封装可视区域大小函数client
			一.client 可视区域 offsetWidth: width + padding + border (披着羊皮的狼) clientWidth: width + ... 
- 【bzoj4715】囚人的旋律  dp
			题目描述 给你一个 $1\sim n$ 的排列 $a_i$ ,若 $i\le j$ 且 $a_i\ge a_j$ ,则 $i$ 到 $j$ 有一条边.现在给你这张图,求既是独立集(任意两个选定点都没有 ... 
- hdu 1086 You can Solve a Geometry Problem too (几何)
			You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ... 
- git log 查看提交记录
			git log 查看提交记录 1. git log 查看提交历史记录2. git log --oneline 或者 git log --pretty=oneline 以精简模式显示3. git log ... 
- CentOS 挂载(U盘NTFS格式,新硬盘,增加交换分区,扩展根分区等)
			1.挂载fat或者fat32分区的U盘 如果是用VM安装的linux,在vm里挂载U盘有两个前提: 第一,主机里的service要启动: 第二,U盘是连接到虚拟机,而不是主机,需要确认这点: 2.使用 ... 
- [2018国家集训队][UOJ449] 喂鸽子 [dp+组合数学]
			题面 传送门 思路 首先,这道题是可以暴力min-max反演+NTT做出来的......但是这个不美观,我来讲一个做起来舒服一点的做法 一个非常basic的idea:我们发现在一只鸽子吃饱以后再喂给它 ... 
- [NOI2009]管道取珠   DP + 递推
			---题面--- 思路: 主要难点在思路的转化, 不能看见要求$\sum{a[i]^2}$就想着求a[i], 我们可以对其进行某种意义上的拆分,即a[i]实际上可以代表什么? 假设我们现在有两种取出某 ... 
