A Telephone company wants to set up its network in a country named byteland. Byteland has N cities. The company wants to join those cities with the end-to-end network. But the problem in Byteland is that the adjacent cities are enemies and do not wants to unite through the network. This problem of byteland also turns out to be a problem for the telephone company.
Your task is to find the minimum number of end-to-end networks required by the company to establish its network on byteland keeping in mind the problem constraints of the country.
Example:
Input: n = 10
Output: 35
Approach
C++
#include <bits/stdc++.h>using namespace std;long long telephoneNetwork(long long n){long long ans;if (n <= 3)return 0;else{n = n - 3;ans = n * (n + 1) / 2 + n;return ans;}}int main(){long long n = 10;cout << telephoneNetwork(n) << "\n";return 0;}
No comments:
Post a Comment