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 ...
随机推荐
- selenium元素定位不到之iframe---基于python
我们在使用selenium的18中定位方式的时候,有时会遇到定位不上的问题,今天我们就来说说导致定位不上的其中一个原因---iframe 问题描述:通过firebug查询到相应元素的id或name等, ...
- NFC学习总结二
移动支付这事情热了总归还是会回归理性,就如同之前的10几年间的几次轮回一样.字面上看,移动支付比支付大也不大可能,有相同,有扩展,有交集有不通才是. NFC这事情也是说了快十年了,真心希望它能回归到其 ...
- “Hello World!”团队——Alpha发布用户使用报告
博客内容: 1.用户体验报告表 2.用户评论截图 3.总结 一.用户体验报告表 用户使用报告 用户序号 用户姓名(化名) 性别 用户职业 使用频次 用户评论 1 小董 女 文学在读硕士 5 1.游戏界 ...
- Beta阶段项目展示博客
Beta阶段项目展示 团队成员的简介 详细见团队简介 角色 姓名 照片 项目经理,策划 游心 策划 王子铭 策划 蔡帜 美工 赵晓宇 美工 王辰昱 开发.架构师 解小锐 开发 陈鑫 开发 李金奇 开发 ...
- c# 计算两个时间的时间差
//计算2个日期之间的天数差 DateTime dt1 = Convert.ToDateTime("2007-8-1"); DateTime dt2 = Convert.ToDat ...
- adb shell input keyevent值所对应的字符
转自:http://blog.csdn.net/chen825919148/article/details/18732041 0 --> "KEYCODE_UNKNOWN" ...
- MongoDB、ElasticSearch、Redis、HBase这四种热门数据库的优缺点及应用场景
MongoDB MongoDB是当今最火爆的NoSQL数据库.MongoDB最早在09年发布,算得上是早期大数据时代的数据库代表作了.随着MongoDB的火爆,研发MongoDB的团队还专门成立了Mo ...
- React Components Template
React Components Template "use strict"; /** * * @author xgqfrms * @license MIT * @copyrigh ...
- SQL Server的全局变量
SQL Service中的全部变量不需要用户参与定义,在任何程序均可随时调用.并且全部变量是以@@开头 全局变量名称 描述 @@CONNECTIONS 返回 SQL Server 自上次启动以来尝试的 ...
- 【BZOJ4892】DNA(后缀数组)
[BZOJ4892]DNA(后缀数组) 题面 BZOJ 洛谷 题解 看到这道题目,我第一反应是\(FFT\)??? 然后大力码出了一个\(FFT\) 就像这样 #include<iostream ...