题目链接: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. 给Nginx配置一个自签名的SSL证书

    转自廖雪峰的官方网站http://www.liaoxuefeng.com/ 要保证Web浏览器到服务器的安全连接,HTTPS几乎是唯一选择.HTTPS其实就是HTTP over SSL,也就是让HTT ...

  2. 测试经验总结(“二次开发”)

    参考原文地址:http://www.51testing.com/html/86/n-3601786.html 不知不觉已经工作五年时间了,从茁壮.康拓普.利鑫云端到现在的惠卡世纪,经历过机顶盒软件(嵌 ...

  3. 通过/etc/rc.local实现开机自动拉起服务

    添加服务到/etc/rc.local 如自动拉起apache服务: /etc/rc.local: #!/bin/sh # # This script will be executed *after* ...

  4. 【bzoj3160】万径人踪灭 FFT

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3160 我是一个傻叉 微笑脸 #include<bits/stdc++.h> #de ...

  5. jQuery取得select选中的值

    $("#sxselect").change(function(){ alert($("#sxselect option:selected").val()); } ...

  6. OSG使用更新回调来更改模型

    OSG使用更新回调来更改模型 转自:http://blog.sina.com.cn/s/blog_668aae7801017gl7.html 使用回调类实现对场景图形节点的更新.本节将讲解如何使用回调 ...

  7. 熟悉Eclipse开发工具

    一.熟悉Eclipse 1.Eclipse是由IBM公司投资4000万美元开发的集成开发工具.它基于Java语言编写,并且是开放源代码的.可扩展的,也是目前最流行的Java集成开发工具之一.另外,IB ...

  8. nginx资源定向 css js路径问题

    今天玩玩项目,学学nginx发现还不错,速度还可以,但是CSS JS确无法使用,原来Iginx配置时需要对不同类型的文件配置规则,真是很郁闷,不过想想也还是很有道理.闲暇之际,把配置贴上来.#user ...

  9. EasyUI组件(窗口组件)

    注意首先要在title后面导入配置文件,前后顺序不能乱 <!-- 1.jQuery的js包 --><script type="text/javascript" s ...

  10. CentOS安装开发组相关的包

    yum groupinstall "Development Tools"   yum groupremove "Development Tools"