Watson gives an integer to Sherlock and asks him: What is the number of divisors of N that are divisible by 2
?.
Example:
Input: n = 8
Output: 3
Approach
C++
#include <bits/stdc++.h>using namespace std;int divisors(int n){int count = 0;for (long i = 2; i * i <= n; i++){if (n % i == 0 && i % 2 == 0)count++;if (n % (n / i) == 0 && ((n / i) != i) && ((n / i) % 2 == 0))count++;}if (n % 2 == 0)count++;return count;}int main(){int n = 8;cout << divisors(n) << "\n";return 0;}
No comments:
Post a Comment