summaryrefslogtreecommitdiffstats
path: root/19/cpp/01-2.cpp
blob: 7ce1a825b3aff534644ca4da69e68b92cb8fcdd1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>

int getFuel(int mass) {
	int fuel = (mass / 3) - 2;
	if (fuel <= 0) return 0;
	return fuel + getFuel(fuel);
}

int main() {
	int mass, sum = 0;
	while (std::cin >> mass) sum += getFuel(mass);
	std::cout << sum << std::endl;
}