1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【AtCoder C++】ABC080 B - Harshad Number

Last updated at Posted at 2024-03-05

学習記録用 - Harshad Number

// 148
// No
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  cin >> N;
  int Harshad = N;
  int sum = 0;
  //各桁の和をsum変数に格納
  //%10で桁取得、//10で進む
  //割り切れば"Yes" else
  while(N > 0){
    sum += N % 10;
    N /= 10;
  }
  
  if (Harshad % sum == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

最初Nの格納用変数Harshadを用意していなくて、wrongが出た!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?