OJ地址:https://vjudge.net/problem/OpenJ_Bailian-2699
對一個整數n,如果其各個位數的數字相加得到的數m能整除n,則稱n爲自整除數.例如21,21%(2+1)==0,所以21是自整除數.現求出從10到n(n < 100)之間的所有自整除數.
Input
有一行,整數n,(10 <= n < 100)
Output
有多行.按從小到大的順序輸出所有大於等於10,小於等於n的自整除數,每行一個自整除數.
Sample Input
47
Sample Output
10
12
18
20
21
24
27
30
36
40
42
45
程序代碼:
#include<cstdio>
#include<cmath>
int main(){
int n,a,b;
scanf("%d",&n);
for(int i=10;i<n;i++){
a=i%10;
b=i/10;
if(i%(a+b)==0){
printf("%d\n",i);
}
}
return 0;
}