题目链接: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(求奇因子的个数)的更多相关文章

  1. LightOJ 1278 - Sum of Consecutive Integers 分解奇因子 + 思维

    http://www.lightoj.com/volume_showproblem.php?problem=1278 题意:问一个数n能表示成几种连续整数相加的形式 如6=1+2+3,1种. 思路:先 ...

  2. Sum of Consecutive Integers LightOJ - 1278(推公式 数学思维)

    原文地址:https://blog.csdn.net/qq_37632935/article/details/79465213 给你一个数n(n<=10^14),然后问n能用几个连续的数表示; ...

  3. Sum of Consecutive Integers

    Sum of Consecutive Integers 题目链接 题意 问N能够分解成多少种不同的连续数的和. 思路 连续数是一个等差数列:$$ \frac{(2a1 + n -1)n}{2} = T ...

  4. 【leetcode74】Sum of Two Integers(不用+,-求两数之和)

    题目描述: 不用+,-求两个数的和 原文描述: Calculate the sum of two integers a and b, but you are not allowed to use th ...

  5. 通过位运算求两个数的和(求解leetcode:371. Sum of Two Integers)

    昨天在leetcode做题的时候做到了371,原题是这样的: 371. Sum of Two Integers Calculate the sum of two integers a and b, b ...

  6. ACM:POJ 2739 Sum of Consecutive Prime Numbers-素数打表-尺取法

    POJ 2739 Sum of Consecutive Prime Numbers Time Limit:1000MS     Memory Limit:65536KB     64bit IO Fo ...

  7. 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 ...

  8. poj 2379 Sum of Consecutive Prime Numbers

                                                                                                        ...

  9. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. ural 1143. Electric Path

    1143. Electric Path Time limit: 1.0 secondMemory limit: 64 MB Background At the team competition of ...

  2. hive 记事本

    hive 0.12 load data overwrite 直接覆盖了数据,不进回收站..... 手动load data 不加overwrite

  3. 【NOI2016】区间 题解

    题目大意: 有n个区间,当有m个区间有公共部分时,求m个区间长度的最大值与最小值之差的最小值. 思路: 按区间的长度从小到大排序,可知连续的几个区间最优,则用两个指针指其头尾,线性扫描,再用线段树区间 ...

  4. flex 遍历Object或者JSON对象内容的实现代码

    private function init():void { //新建对象 var obj:Object = new Object(); //增加key-value obj["name&qu ...

  5. 学习PHP第一天-----简单登录

    <!DOCTYPE html> <html> <head> <title>初级登录界面</title> </head> < ...

  6. ArrayList和Vector的扩容机制

    ArrayList和Vector都是继承了相同的父类和实现了相同的接口.如下 public class Vector<E> extends AbstractList<E> im ...

  7. continue 语句

    停止循环的当前迭代,并开始新的迭代. continue [label]; 可选的 label 参数指定 continue 应用于哪条语句. 说明 只能在 while.do...while.for.或  ...

  8. Jenkins 2.7.3 LTS 发布

    更新如下: Stop A/B testing of the remoting JNLP3 protocol due to the known issues. The protocol can be e ...

  9. Perform UPSERT / INSERT OR UPDATE against a SQLite Database

    Option 1: You can afford deleting the row In other words, you don't have foreign key, or if you have ...

  10. 在mapreduce中做分布式缓存的问题

    一.问题描述: 主要解决一个问题,就是两个表做join,两个表都够大,单个表都无法装入内存. 怎么做呢?思路就是对做join的字段做排序两个表都排序,然后针对一个表a逐行读取,希望能够在内存中加载到另 ...