# Daily Coding Challenge #85

This is a series of Daily Coding Challenge. Each day I show a few solutions written in C++. The questions are from coding practice/contest sites such as HackerRank, LeetCode, Codeforces, Atcoder and etc.

/*
LeetCode - Power of Four

Given an integer (signed 32 bits), write a function to check whether it is a power of 4.

Example 1:

Input: 16
Output: true
Example 2:

Input: 5
Output: false
Follow up: Could you solve it without loops/recursion?
*/

class Solution {
public:
bool isPowerOfFour(int num) {
// 4: 100
// 16: 10000
// obversation:
// count of 1s is 1 and the number of trailing zeros is even
return __builtin_popcount(num)==1 && // only 1 bit is set
(__builtin_ctz(num)&1)==0;    // with even trailing zeros
}
};

/*
Hello 2019 - B. Petr and a Combination Lock
https://codeforces.com/problemset/problem/1097/B
*/

#include <bits/stdc++.h>
using namespace std;
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll;
const ll MOD = 1000000007;

int main()
{
FAST_INP;
int n;
cin >> n;
vector<int> a(n);
for(int &x:a) cin >> x;
int ans=0;
for(int i=0;i<n;i++){
else ans-=a[i];
}
if(ans%360==0) {
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
return 0;
}

The source code is available in corresponding repo below. Star and watch for timely updates!

## wingkwong / atcoder

Posted on by:

### Wing-Kam

Consultant by day. Developer by night. AWS certified. Exploring #CloudNative currently.