492A - Vanya and Cubes - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

n=int(input())
i=1
c=0
j=2
while(n>=i):
    n=n-i
    c+=1
    i+=j
    j+=1
print(c)

C++ Code:

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include<string>
#include<map>
using namespace std;

long long factorial(long long n)
{
	if (n == 1)
		return 1;
	return n * factorial(n - 1);
}

vector<int> primeFactorization(int n)
{
	vector<int> v;
	for (int i = 2;i * i <= n;i++)
	{
		if (n % i == 0)
		{
			while (n % i == 0)
			{
				n /= i;
				v.push_back(i);
			}
		}
	}
	if (n != 1)
		v.push_back(n);
	return v;
}

long long  GCD(long long  n, long long k)
{
	return k == 0 ? n : GCD(k, n % k);
}

long long  LCM(long long  n, long long k)
{
	return n / GCD(n, k) * k;
}

long long sum(long long a)
{
	return (a * (a + 1)) / 2;
}

long long oddSum(long long a)
{
	return  ((a + 1) / 2) * ((a + 1) / 2);
}

long long evenSum(long long a)
{
	return sum(a) - oddSum(a);
}

bool isPrime(long long a)
{
	if (a <= 1)
		return false;
	for (long long i = 2;i * i <= a;i++)
	{
		if (a % i == 0)
		{
			return 0;
		}
	}
	return true;
}

vector<long long>Divisiors(long long n)
{
	vector<long long>v;
	for (long long i = 1;i * i <= n;i++)
	{
		if (n % i == 0)
		{
			if (n / i == i)
				v.push_back(i);
			else
			{
				v.push_back(i);
				v.push_back(n / i);
			}
		}
	}
	return v;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,sum=0,total=0;
	cin >> n ;
	int ctr = 0;
	for (int i = 1;i <= n;i++)
	{
		if (total> n)
			break;
		
		
		sum+= i ;
		total += sum;
		ctr++;
		//cout << sum << "\n";
	}
	if (ctr <=1)
		cout << "1";
	else
	cout << ctr-1;
	return 0;
}


Comments

Submit
0 Comments
More Questions

1582C - Grandma Capa Knits a Scarf
492A - Vanya and Cubes
217A - Ice Skating
270A - Fancy Fence
181A - Series of Crimes
1638A - Reverse
1654C - Alice and the Cake
369A - Valera and Plates
1626A - Equidistant Letters
977D - Divide by three multiply by two
1654B - Prefix Removals
1654A - Maximum Cake Tastiness
1649A - Game
139A - Petr and Book
1612A - Distance
520A - Pangram
124A - The number of positions
1041A - Heist
901A - Hashing Trees
1283A - Minutes Before the New Year
1654D - Potion Brewing Class
1107B - Digital root
25A - IQ test
785A - Anton and Polyhedrons
1542B - Plus and Multiply
306A - Candies
1651C - Fault-tolerant Network
870A - Search for Pretty Integers
1174A - Ehab Fails to Be Thanos
1169A - Circle Metro