LightOj 1278 - Sum of Consecutive Integers(求奇因子的个数)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1278
题意:给你一个数n(n<=10^14),然后问n能用几个连续的数表示;
例如: 15 = 7+8 = 4+5+6 = 1+2+3+4+5,所以15对应的答案是3,有三种;
我们现在相当于已知等差数列的和sum = n, 另首项为a1,共有m项,那么am = a1+m-1;
sum = m*(a1+a1+m-1)/2 -----> a1 = sum/m - (m-1)/2
a1 和 m 一定是整数,所以sum%m = 0 并且(m-1)%2=0, 所以m是sum的因子,并且要是奇数;
所以我们只要求n的奇数因子的个数即可,求一个数的因子个数是所有素数因子的幂+1,相乘起来就是,那么素数只有2是偶数,
所以奇数因子的个数就是所有 素数因子(除2之外)+1的乘积,当然要m一定要大于1,所以要减去1,除去因子1的情况;
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h> using namespace std; typedef long long LL; const double eps = 1e-;
const int N = 1e7+; int p[N/], k;
bool f[N]; void Init()
{
for(int i=; i<N; i++)
{
if(!f[i]) p[k++] = i;
for(int j=i+i; j<N; j+=i)
f[j] = true;
}
} int main()
{
Init(); int T, t = ; scanf("%d", &T); while(T --)
{
LL n, ans = ; scanf("%lld", &n); int flag = ; for(int i=; i<k && (LL)p[i]*p[i]<=n; i++)
{
LL cnt = ;
while(n%p[i] == )
{
cnt ++;
n /= p[i];
}
if(i)///不能算 2 ;
ans *= cnt+;
}
if(n > )
ans *= ; ans -= ;///减去1的情况; printf("Case %d: %lld\n", t++, ans);
}
return ;
}
LightOj 1278 - Sum of Consecutive Integers(求奇因子的个数)的更多相关文章
- LightOJ 1278 - Sum of Consecutive Integers 分解奇因子 + 思维
http://www.lightoj.com/volume_showproblem.php?problem=1278 题意:问一个数n能表示成几种连续整数相加的形式 如6=1+2+3,1种. 思路:先 ...
- Sum of Consecutive Integers LightOJ - 1278(推公式 数学思维)
原文地址:https://blog.csdn.net/qq_37632935/article/details/79465213 给你一个数n(n<=10^14),然后问n能用几个连续的数表示; ...
- Sum of Consecutive Integers
Sum of Consecutive Integers 题目链接 题意 问N能够分解成多少种不同的连续数的和. 思路 连续数是一个等差数列:$$ \frac{(2a1 + n -1)n}{2} = T ...
- 【leetcode74】Sum of Two Integers(不用+,-求两数之和)
题目描述: 不用+,-求两个数的和 原文描述: Calculate the sum of two integers a and b, but you are not allowed to use th ...
- 通过位运算求两个数的和(求解leetcode:371. Sum of Two Integers)
昨天在leetcode做题的时候做到了371,原题是这样的: 371. Sum of Two Integers Calculate the sum of two integers a and b, b ...
- 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 ...
- 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 ...
随机推荐
- ScriptManager和ClientScript的区别
ClientScript获取用于管理脚本.注册脚本和向页面添加脚本的ClientScriptManager对象. ScriptManager.RegisterStartupScript方法和Clien ...
- SQL: See the TSQL underneath the sp_execute calls
When use SQL Server Profiler, on the Events Selection tab, check Show all events; Find the Store Pro ...
- BZOJ3515 : EvenPaths
首先拓扑排序,并将障碍点按拓扑序平均分成两半. 那么一条$0$到$1$的路径一定是形如: $0$->前一半点->后一半点->第一个后一半障碍点->后一半点->$1$. 对 ...
- 洛谷 P1031 均分纸牌 Label:续命模拟QAQ
题目描述 有 N 堆纸牌,编号分别为 1,2,…, N.每堆上有若干张,但纸牌总数必为 N 的倍数.可以在任一堆上取若于张纸牌,然后移动. 移牌规则为:在编号为 1 堆上取的纸牌,只能移到编号为 2 ...
- HDU 4751 Divide Groups
题目链接 比赛时候,建图建错了.大体算法想到了,不过很多细节都没想好. #include <cstdio> #include <cstring> #include <cm ...
- 【noiOJ】p8211 (PS:二分浮点数的精度问题)
05:派 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 我的生日要到了!根据习俗,我需要将一些派分给大家.我有N个不同口味.不同大小的派.有F个朋友会来参加 ...
- 【JAVA】LOG4J使用心得
一.LOG4J基础: 1.日志定义 简单的Log4j使用只需要导入下面的包就可以了 // import log4j packages import org.apache.log4j.Lo ...
- gui学习
GUI 图形用户界面(Graphical User Interface,简称 GUI,又称图形用户接口)是指采用图形方式显示的计算机操作用户界面 有名的实现 : ucgui . 实现围绕几个问题: ...
- Java_Java中动态加载jar文件和class文件
转自:http://blog.csdn.net/mousebaby808/article/details/31788325 概述 诸如tomcat这样的服务器,在启动的时候会加载应用程序中lib目录下 ...
- Picture effect of JavaScript
每隔一定时间跟换图片Img = new Array("image/2.jpg","image/1.jpg","image/3.jpg",&q ...