Problem:
Score : 200 points

Problem Statement

An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10.

Given an integer N, determine whether it is a Harshad number.

Constraints

1?N?10^8

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print Yes if N is a Harshad number; print No otherwise.

Sample Input 1

12

Sample Output 1

Yes

f(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.

Sample Input 2

57

Sample Output 2

No

f(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.

Sample Input 3

148

Sample Output 3

No

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int A = N;
  int C = N;
  int sum = 0;
  int B = 1;
 
  for(int i = 0;N == 0; i++){
    N /= 10;
    for(int j = 0;j <= i;j++){
      B *=10;
    }
    A %= B;
    sum += A;
    A = C - (A * B);
  }
  
  if(C % sum == 0){
    cout << "yes" << endl;
  }
  
  else if(C % sum){
    cout << "No" << endl;
  }
  
}