E - Digit Sums (水题)

Problem Statement

令S(N) : 十进制表示法中,N 的各位数字相加之和. 例如, S(101) = 1 + 0 + 1 = 2.

给你一个整数 N, 判断 S(N) 能否整除 N .

Constraints

1 <= N <= 10^9

Input

输入仅一行,一个整数N

Output

如果 S(N) 能整除 N, 输出 Yes; 否则, 输出 No.

Sample Input 1

12

Sample Output 1

Yes

输入N = 12. S(12) = 1 + 2 = 3, S(N) 能整除 N.

Sample Input 2

101

Sample Output 2

No

S(101) = 1 + 0 + 1 = 2 , S(N) 不能整除 N .

写这个水题的原因是当时比赛居然没过,这么简单的题。。。(看来当时太弱了)

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int sum=0,m=0,b=n;
	while(n>0){
		m=n%10;
		n/=10;
		sum+=m;
	}
	if(b%sum==0) cout<<"Yes"<<endl;
	else if(b%sum!=0) cout<<"No"<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41555192/article/details/82501988