HackerLand Enterprise is adopting a new viral advertising strategy. When they launch a new product, they advertise it to exactly people on social media.
On the first day, half of those people (i.e., ) like the advertisement and each shares it with of their friends. At the beginning of the second day, people receive the advertisement.
Each day, of the recipients like the advertisement and will share it with friends on the following day. Assuming nobody receives the advertisement twice, determine how many people have liked the ad by the end of a given day, beginning with launch day as day .
For example, assume you want to know how many have liked the ad by the end of the day.
Input Format
A single integer, , denoting a number of days.
Output Format
Print the number of people who liked the advertisement during the first days.
Question From hackerrank.
Solution in C# -
class Solution {
static int viralAdvertising(int n) {
int people = 5;
int result = 0;
for(int i=0; i<n; i++)
{
people = people/2;
result += people;
people *= 3;
}
return result;
}
static void Main(string[] args) {
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
int n = Convert.ToInt32(Console.ReadLine());
int result = viralAdvertising(n);
textWriter.WriteLine(result);
textWriter.Flush();
textWriter.Close();
}
}
Post a Comment