• Loading...

Problem 3: Factorials

Points:

Small Case: 10 Answer: 11

Large Case: 20 Answer: 590030438399

Given n, Let a1+a2+a3+...+ak = n!, where a1, a2, ..., ak are consecutive positive integers with k>1.

Let {k,a1,a2,..,ak} be any set. Find number of different such sets.

The problem statement has been updated.
a1, a2, a3... ak can only be positive integers.

Small Case: n = 7

Large Case: n = 77


Solution:

Number of ways of representing a number M as sum of one or more consecutive integers is equal to the number of odd positive divisors of M.

Considering representation as sum of even number of consecutive integers, we have:
M = (x − y + 1) + ... + x + (x + 1) + ... + (x + y) for some integers x and y, y>0.
So, M = (x + 1/2) * (2*y) = (2*a + 1)*b
Number of ways of solving these equations is equal to number of positive odd divisors of M.

Now, considering representation as sum of odd number of consecutive integers, we have:
M = (x − y) + ... + x + ... + (x + y) for some integers x and y, y>=0
So, M = x*(2*y + 1)

Now, let M = x+(x+1)+...+y = (1-x)+...(x-1) + x+(x+1)+...+y
Thus, for certain x and y, there are two ways of representation of M. One starting with positive integer 'x' and other starting with negative integer '1-x'.
Hence, only half of the representations of M start with a positive integer.

Number of ways of representing a number as sum of one consecutive integer is one i.e. the number itself.
Therefore, number of ways of representing M as two or more consecutive positive integers is one less than the number of positive odd divisors of M.


Code:


#include<stdio.h>
#define MAX 100
#define N 77

void sieve(int prime[])
{
	int i,j=0,k,temp[MAX]={0};
	for(i=2;i<MAX;i++)
	{
		if(temp[i]==0)
		{
			prime[j++]=i;
			for(k=2*i;k<MAX;k+=i)
			{
				temp[k]=1;
			}
		}
	}
}

int main()
{
	int i,prime[MAX];
	long long no_positive_odd_divisors=1;
	sieve(prime);
	i=1;
	while(prime[i]<=N)
	{
		int temp = prime[i];
		int quotient = N/temp;
		int sum=0;
		while(quotient!=0)
		{
			sum += quotient;
			temp *= prime[i];
			quotient = N/temp;
		}
		no_positive_odd_divisors *= sum+1;
		i++;
	}
	long long ways_of_representation = no_positive_odd_divisors - 1;
	printf("%lld\n",ways_of_representation);
}

Submit your solution

You need to be logged in to submit a solution.

discussions


porshIncorrect example
Q:For n=24, there are 3 possible sets viz.1){3,7,8,9} 2){16,-6,-7,...,7,8,9}3){47,-23,-22,...,23,24}
A:Negative numbers are not allowed.Problem Statement has been updated.
dethstika is also negative
Q:in the set of k elements some could be negative right?
A:No,every element is positive
rishudiffrent sets
Q:what do u mean by different sets of numbers?
A:Two sets are considered different if they differ at least one element.
quimeyCan you give us an example?
Q:A small example would be nice, like for n=4 or n=5.
A:For n=4, the value n!=24. It can be represented as sum of consecutive positive integers in only one way i.e. 7+8+9.

post a question

Loading...

Problem 1
Problem 2
Problem 3
Problem 4
Problem 5 (bonus) Expired
Problem 1
Problem 2
Problem 3
Problem 4 (bonus) Expired
Top Scorers
rng_58 235
Anton_Lunyov 225
tourist 190
Silence 180
cedricl2 175
cgy4ever 175
DrKorbin 165
Koen 155
bbbasic 150
lunae_2 150
Submissions
Problem 1
10 pt
not submitted
98
submissions

19
correct (19 %)



25 pt
not submitted
2
submissions

1
correct (50 %)


Problem 2
5 pt
not submitted
95
submissions

38
correct (40 %)



10 pt
not submitted
19
submissions

15
correct (78 %)


Problem 3
5 pt
not submitted
153
submissions

117
correct (76 %)



15 pt
not submitted
44
submissions

25
correct (56 %)


Problem 4
10 pt
not submitted
152
submissions

54
correct (35 %)



15 pt
not submitted
23
submissions

10
correct (43 %)


Problem 5
10 pt
not submitted
36
submissions

28
correct (77 %)



20 pt
not submitted
6
submissions

2
correct (33 %)


Problem 6
5 pt
not submitted
41
submissions

29
correct (70 %)



10 pt
not submitted
15
submissions

14
correct (93 %)


Problem 7
5 pt
not submitted
38
submissions

17
correct (44 %)



10 pt
not submitted
16
submissions

15
correct (93 %)


Problem 8
5 pt
not submitted
127
submissions

104
correct (81 %)



15 pt
not submitted
47
submissions

34
correct (72 %)


Problem 9
5 pt
not submitted
86
submissions

35
correct (40 %)



15 pt
not submitted
16
submissions

15
correct (93 %)


Problem 10
5 pt
not submitted
45
submissions

23
correct (51 %)



15 pt
not submitted
15
submissions

14
correct (93 %)


Problem 11
5 pt
not submitted
81
submissions

27
correct (33 %)



15 pt
not submitted
8
submissions

3
correct (37 %)


Problem 12
5 pt
not submitted
104
submissions

88
correct (84 %)



10 pt
not submitted
31
submissions

21
correct (67 %)