第四届吉林省大学生程序设计大赛个人解题报告 Problem A: Harshad Number

来源:互联网 发布:做淘宝客服有什么前途 编辑:程序博客网 时间:2024/04/29 05:47

   Problem A: Harshad Number


Welcome to 2010 Jilin Province Collegiate Programming Contest. Do you know 2010 is a magic number? If you add up all the digits of 2010, that is 3, it is just one factor of 2010. The number who has this character is called Harshad number. A Harshad number, or Niven number in a given number base, is an integer that is divisible by the sum of its digits when written in that base. Harshad numbers were defined by D. R. Kaprekar, a mathematician from India. The word "Harshad" comes from the Sanskrit "harṣa", meaning "great joy". The Niven numbers take their name from Ivan M. Niven from a paper delivered at a conference on number theory in 1997. All integers between zero and n are Harshad numbers in base n. The Harshad number is rare in all natural numbers. The ratio is about 10% decreasing with the number value.   Your task is to list all the Harshad number between 1000 and 9999 orderly. We just consider the normal decimal base.


Input
This problem has no input


Output
You should output each Harshad number in one line orderly.


Sample Output
1000
……
2010
……
9990
 
Not all the numbers are listed in the sample. There are just the first, the last, and 2010 itself. The ellipsis expresses what you should calculate.

 

这道题是一道十足的水题,也就要求你打印1000 - 9999中,能除于自己每一位数加和的数。代码实现如下:

原创粉丝点击