Light OJ 1278 Sum of Consecutive Integers N拆分成连续整数和

题目来源:Light OJ 1278 Sum of Consecutive Integers

题意:N拆分成连续整数和的方案数

思路:奇因数的个数

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
//筛素数
const int maxn = 10000010;
bool vis[maxn];
int prime[1000000];

int sieve(int n)
{
	memset(vis, 0, sizeof(vis));
	vis[0] = vis[1] = 1;
	int c = 0;
	for(int i = 2; i <= n; i++)
		if(!vis[i])
		{
			prime[c++] = i;
			for(int j = 2*i; j <= n; j += i)
				vis[j] = 1;
		}
	return c;
}

int main()
{
	int c = sieve(10000000);
	int cas = 1;
	int T;
	scanf("%d", &T);
	while(T--)
	{
		long long n, ans = 1;
		scanf("%lld", &n);
		while(n%2 == 0)
			n /= 2;
		for(int i = 0; i < c && (long long)prime[i]*prime[i] <= n; i++)
		{
			if(prime[i] > n)
				break;
			if(n % prime[i] == 0)
			{
				long long sum = 1;
				while(n % prime[i] == 0)
				{
					sum++;
					n /= prime[i];
				}
				ans *= sum;
			}
		}
		if(n > 1 && (n&1))
			ans *= 2;
		printf("Case %d: %lld\n", cas++, ans-1);
	}
	return 0;
}

Light OJ 1278 Sum of Consecutive Integers N拆分成连续整数和

时间: 2024-10-09 03:48:07

Light OJ 1278 Sum of Consecutive Integers N拆分成连续整数和的相关文章

LIGHT OJ 1278 Sum of Consecutive Integers(奇因子的个数)

题目链接:传送门 题意: 将给定的n分成 连续的数的和,至少有两个数,看能有多少种方案. 分析: a + (a + 1) + (a + 2) + ... +(a + k - 1) = n; ===> (2*a + k - 1) * k = 2*n; ===> (2*a - 1)*k = 2*n - k*k; ===> 2*a - 1 = 2*n/k - k; 等式的左边为奇数,那么右边也必须为奇数,则k必须为n的奇约数 因此将n素因子分解就可以了 代码如下: #include <i

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 a

Light OJ 1272 Maximum Subset Sum 高斯消元 最大XOR值

题目来源:Light OJ 1272 Maximum Subset Sum 题意:选出一些数 他们的抑或之后的值最大 思路:每个数为一个方程 高斯消元 从最高位求出上三角 消元前k个a[i]异或和都能有消元后的异或和组成 消元前 k 个 a[i] a[i]异或和都能有消元后的 异或和都能有消元后的 p 个 a[i] a[i]的异或 的异或 保证每一列只有一个1 消元后所有A[i]抑或起来就是答案 #include <cstdio> #include <cstring> #inclu

light oj 1348 树链剖分(单点更新区间求值)

http://lightoj.com/volume_showproblem.php?problem=1348 Finally the Great Magical Lamp was in Aladdin's hand. Now he wanted to return home. But he didn't want to take any help from the Genie because he thought that it might be another adventure for hi

POJ 2739 Sum of Consecutive Prime Numbers(水题)

Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20560   Accepted: 11243 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio

Light OJ 1411 Rip Van Winkle`s Code 线段树成段更新

题目来源:Light OJ 1411 Rip Van Winkle`s Code 题意:3中操作 1种查询 求区间和 其中每次可以把一段区间从左到右加上1,2,3,...或者从右到左加上...3,2,1 或者把某个区间的数都置为v 思路:我是加了6个域 add是这段区间每个数都要加上add  add是这么来的 对与123456...这个等差数列 可能要分为2个区间 那么我就分成123和123 两个右边的等差数列每个数还应该加上3 所以右区间add加3 v是这个区间都要置为v 他的优先级最高 b是

poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0

Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19697   Accepted: 10800 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio

poj 2379 Sum of Consecutive Prime Numbers

Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24498   Accepted: 13326 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio

poj 2739 Sum of Consecutive Prime Numbers 尺取法

Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21924   Accepted: 11996 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio