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

本文介绍了一种特殊的数——Harshad数,并提供了一个简单的C++程序,用于列出1000到9999之间的所有Harshad数。Harshad数是一种可以被自己的各位数字之和整除的数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   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中,能除于自己每一位数加和的数。代码实现如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值