function getNumberOfGames(x) { const games = Math.floor(x / 2); const excessTeam = x % 2; if (!games) return games; else if (!excessTeam && games === 1) return 1; else { const nextTeamsCount = games + excessTeam; return games + getNumberOfGames(nextTeamsCount); } } let sum = 0; for (let i = 1; i <= 100; i++) { sum += getNumberOfGames(i) } console.log(sum); /// output: // 4950
(ваш голос учтен)