-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviralAdvertising.cpp
More file actions
44 lines (32 loc) · 1022 Bytes
/
viralAdvertising.cpp
File metadata and controls
44 lines (32 loc) · 1022 Bytes
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
38
39
40
41
42
43
44
#include <bits/stdc++.h>
using namespace std;
// Complete the viralAdvertising function below.
/***********************************************/
/** Looks like this ****************************/
/** Day Shared Liked Cumulative ****************/
/** 1 5 2 2 ****************/
/** 2 6 3 5 ****************/
/** 3 9 4 9 ****************/
/** 4 12 6 15 ****************/
/** 5 18 9 24 ****************/
/***********************************************/
int viralAdvertising(int n) {
int noPeople = 0, shared = 5, liked = 0;
for (int i = 1; i <= n; i++) {
liked = shared/2;
noPeople = noPeople + liked;
shared = liked*3;
}
return noPeople;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
int n;
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int result = viralAdvertising(n);
fout << result << "\n";
fout.close();
return 0;
}