-
Notifications
You must be signed in to change notification settings - Fork 694
/
Copy pathSolution.cs
37 lines (31 loc) · 950 Bytes
/
Solution.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
Problem: https://www.hackerrank.com/challenges/strange-advertising/problem
C# Language Version: 6.0
.Net Framework Version: 4.5.2
Thoughts :
1. Let the number of days for advertisement strategy runs be n.
2. Let total advertisement likes in n days be l. Set l = 0.
3. Let people who received advertisement on day 1 by m. Set m = 5
4. Start a loop which run n times with below steps in each iteration:
4.1 Set l = l + floor(m/2)
4.2 m = floor(m/2)*3
5. Print l
Time Complexity: O(n)
Space Complexity: O(1)
*/
using System;
class Solution
{
static void Main(String[] args)
{
var numberOfDays = int.Parse(Console.ReadLine());
var totalLikes = 0D;
var AdShareCount = 5.0;
for (int i = 0; i < numberOfDays; i++)
{
totalLikes += Math.Floor(AdShareCount / 2);
AdShareCount = Math.Floor(AdShareCount / 2) * 3;
}
Console.WriteLine(totalLikes);
}
}