8.一个自然数的末两位为19,各位数字和为19,且能被19整除?

如题所述

可以通过断尾法来寻找19的倍数,但是效率很低。同时又要求这个自然数的各位数字之和为19,这没有直接的数学推导方法。因此,只能通过编程来进行枚举搜索。

设这个自然数为100n+19,根据余数定理,19 mod 19 = 0,所以,只需要在 n=19k(k为自然数)中找出n的各位数字之和等于 19-1-9=9 的数就可以了。

很明显,这样的自然数有无数个。

我们可以编程求出四字节整数范围内(2³¹-1=2147483647)的所有符合条件的结果。一共有487个。程序运行时间小于千分之一秒。

具体如下:

17119,34219,51319,102619,171019,205219,222319,342019,410419,513019,530119,701119,1026019,1043119,1060219,1111519,1214119,1231219,1402219,1710019,2000719,2052019,2103319,2120419,2223019,2240119,2411119,3112219,3300319,3420019,4001419,4104019,4121119,5010319,5130019,5301019,6002119,7011019,10003519,10020619,10106119,10123219,10140319,10260019,10311319,10431019,10602019,11012419,11115019,11132119,11200519,11303119,11320219,12004219,12021319,12141019,12312019,12500119,13013119,13030219,13201219,14022019,14210119,17100019,20007019,20024119,20041219,20212219,20400319,20520019,21033019,21050119,21101419,21204019,21221119,22110319,22230019,22401019,23102119,24111019,25000219,30010519,30113119,30130219,30301219,31002319,31122019,31310119,32011219,33003019,33020119,34200019,40014019,40031119,40202119,41040019,41211019,42100219,50000419,50103019,50120119,51300019,52001119,53010019,60021019,70110019,100000819,100035019,100052119,100103419,100120519,100206019,100223119,100240219,100411219,101061019,101112319,101232019,101300419,101403019,101420119,102001519,102104119,102121219,102600019,103010419,103113019,103130119,103301119,104002219,104310019,105011119,106020019,110004319,110021419,110124019,110141119,110312119,110500219,111013219,111030319,111150019,111201319,111321019,112005019,112022119,112210219,113031019,113202019,115100119,120042019,120110419,120213019,120230119,120401119,121102219,121410019,122111119,123000319,123120019,125001019,130011319,130131019,130302019,131003119,131020219,132012019,132200119,140100319,140220019,142101019,150001219,151010119,171000019,200001619,200070019,200104219,200121319,200241019,200412019,200600119,201010519,201113119,201130219,201301219,202002319,202122019,202310119,203011219,204003019,204020119,205200019,210005119,210022219,210210319,210330019,210501019,211014019,211031119,211202119,212040019,212211019,213100219,220111219,221000419,221103019,221120119,222300019,223001119,224010019,230012119,230200219,231021019,240101119,241110019,250002019,300002419,300105019,300122119,300310219,301011319,301131019,301302019,302003119,302020219,303012019,303200119,310023019,310040119,310211119,311100319,311220019,313101019,320112019,320300119,321001219,322010119,330030019,330201019,342000019,400003219,400020319,400140019,400311019,401012119,401200219,402021019,410400019,411101119,412110019,420010219,421002019,440000119,500004019,500021119,501030019,501201019,510110119,513000019,520011019,530100019,600210019,611000119,701100019,1000008019,1000025119,1000042219,1000110619,1000213219,1000230319,1000350019,1000401319,1000521019,1001034019,1001051119,1001102419,1001205019,1001222119,1001410219,1002060019,1002111319,1002231019,1002402019,1003000519,1003103119,1003120219,1004112019,1004300119,1005001219,1006010119,1010011519,1010114119,1010131219,1010302219,1010610019,1011003319,1011020419,1011123019,1011140119,1011311119,1012012219,1012200319,1012320019,1013004019,1013021119,1014030019,1014201019,1020015019,1020032119,1020100519,1020203119,1020220219,1021041019,1021212019,1021400119,1022101219,1023110119,1026000019,1030001419,1030104019,1030121119,1031010319,1031130019,1031301019,1032002119,1033011019,1040022019,1040210119,1043100019,1050111019,1051000219,1060200019,1100043019,1100060119,1100111419,1100214019,1100231119,1100402119,1101000619,1101103219,1101120319,1101240019,1101411019,1102112119,1102300219,1103001319,1103121019,1104010219,1105002019,1110012319,1110132019,1110200419,1110303019,1110320119,1111004119,1111021219,1111500019,1112013019,1112030119,1112201119,1113210019,1120050019,1120101319,1120221019,1121110219,1122102019,1124000119,1130002219,1130310019,1131011119,1132020019,1141100119,1151001019,1200112219,1200300319,1200420019,1201001419,1201104019,1201121119,1202010319,1202130019,1202301019,1203002119,1204011019,1210013119,1210030219,1210201219,1211022019,1211210119,1214100019,1220102119,1221111019,1222000219,1230003019,1230020119,1231200019,1250010019,1300010419,1300113019,1300130119,1300301119,1301002219,1301310019,1302011119,1303020019,1310031019,1310202019,1312100119,1320000319,1320120019,1322001019,1400011219,1401003019,1401020119,1402200019,1410100219,1420001119,1421010019,1500012019,1500200119,1510101019,1710000019,2000016019,2000033119,2000050219,2000101519,2000204119,2000221219,2000700019,2001042019,2001110419,2001213019,2001230119,2001401119,2002102219,2002410019,2003111119,2004000319,2004120019,2006001019,2010002419,2010105019,2010122119,2010310219,2011011319,2011131019,2011302019,2012003119,2012020219,2013012019,2013200119,2020023019,2020040119,2020211119,2021100319,2021220019,2023101019,2030112019,2030300119,2031001219,2032010119,2040030019,2040201019,2052000019,2100051019,2100102319,2100222019,2100410119,2101111219,2102000419,2102103019,2102120119,2103300019,2104001119,2105010019,2110003219,2110020319,2110140019,2110311019,2111012119,2111200219,2112021019,2120400019,2121101119,2122110019,2130010219,2131002019,

total = 487

附:fortran代码,具体算法见绿色字体注释

温馨提示:答案为网友推荐,仅供参考
相似回答