Skip to content

Commit

Permalink
some solution added
Browse files Browse the repository at this point in the history
  • Loading branch information
avishkar2001 authored Oct 4, 2021
1 parent 67a7224 commit d9489ba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 21. Viral Advertising/Viral Advertising.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
int n;
cin >> n; //Taking input
int resultwillbe = 2,likeaarecurrently = 2;
//using for loop
for(int i = 2; i <= n; i++){
likeaarecurrently*=3; //Incrementing
likeaarecurrently = likeaarecurrently/2;
resultwillbe+=likeaarecurrently;
}
cout << resultwillbe << endl; //Printing Output
return 0;
}
15 changes: 15 additions & 0 deletions 21. Viral Advertising/Viral Advertising.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import math
input_str = input()
try:
n = int(input_str)
except:
print("An error occurred while parsing the required input as integer.")
if n <= 0 or n >= 51:
print("Bad input specified! Please try again")
result = 0
people = 5
for day in range(1, n + 1):
half = math.floor(people / 2)
result += half
people = 3 * half
print(result)

0 comments on commit d9489ba

Please sign in to comment.