Self Numbers

Time limit1sMemory limit256 MB

Summary
Print all self numbers up to 10000, that is, numbers with no generator under d(n) = n + digit sum of n.
Level

Easy3 of 10

Topics
Implementation, Math, Array, Brute force
Solved
No attempts yet

Problem

A self number is a number named in 1949 by the Indian mathematician D. R. Kaprekar. For a positive integer nn, define the function d(n)d(n) as nn plus the sum of the digits of nn. For example, d(75)=75+7+5=87d(75) = 75 + 7 + 5 = 87.

Given a positive integer nn, we can build the infinite sequence n,d(n),d(d(n)),d(d(d(n))),…n, d(n), d(d(n)), d(d(d(n))), \dots. For example, starting from 33 the next number is 33+3+3=3933 + 3 + 3 = 39, then 39+3+9=5139 + 3 + 9 = 51, then 51+5+1=5751 + 5 + 1 = 57, producing the sequence:

33,39,51,57,69,84,96,111,114,120,123,129,141,…33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, \dots

Here nn is called a generator of d(n)d(n). In the sequence above, 33 is a generator of 39, 39 is a generator of 51, and 51 is a generator of 57. A number can have more than one generator; for example, 101 has two generators, 91 and 100.

A number that has no generator is called a self number. There are 13 self numbers less than 100:

1,3,5,7,9,20,31,42,53,64,75,86,971, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86, 97

Write a program that prints every self number less than or equal to 10000, one per line.

Input

There is no input.

Output

Print every self number less than or equal to 10000 in increasing order, one per line.

Examples1

  1. Example 1

    Input
    Expected output
    1
    3
    5
    7
    9
    20
    31
    42
    53
    64
    75
    86
    97
    108
    110
    121
    132
    143
    154
    165
    176
    187
    198
    209
    211
    222
    233
    244
    255
    266
    277
    288
    299
    310
    312
    323
    334
    345
    356
    367
    378
    389
    400
    411
    413
    424
    435
    446
    457
    468
    479
    490
    501
    512
    514
    525
    536
    547
    558
    569
    580
    591
    602
    613
    615
    626
    637
    648
    659
    670
    681
    692
    703
    714
    716
    727
    738
    749
    760
    771
    782
    793
    804
    815
    817
    828
    839
    850
    861
    872
    883
    894
    905
    916
    918
    929
    940
    951
    962
    973
    984
    995
    1006
    1021
    1032
    1043
    1054
    1065
    1076
    1087
    1098
    1109
    1111
    1122
    1133
    1144
    1155
    1166
    1177
    1188
    1199
    1210
    1212
    1223
    1234
    1245
    1256
    1267
    1278
    1289
    1300
    1311
    1313
    1324
    1335
    1346
    1357
    1368
    1379
    1390
    1401
    1412
    1414
    1425
    1436
    1447
    1458
    1469
    1480
    1491
    1502
    1513
    1515
    1526
    1537
    1548
    1559
    1570
    1581
    1592
    1603
    1614
    1616
    1627
    1638
    1649
    1660
    1671
    1682
    1693
    1704
    1715
    1717
    1728
    1739
    1750
    1761
    1772
    1783
    1794
    1805
    1816
    1818
    1829
    1840
    1851
    1862
    1873
    1884
    1895
    1906
    1917
    1919
    1930
    1941
    1952
    1963
    1974
    1985
    1996
    2007
    2022
    2033
    2044
    2055
    2066
    2077
    2088
    2099
    2110
    2112
    2123
    2134
    2145
    2156
    2167
    2178
    2189
    2200
    2211
    2213
    2224
    2235
    2246
    2257
    2268
    2279
    2290
    2301
    2312
    2314
    2325
    2336
    2347
    2358
    2369
    2380
    2391
    2402
    2413
    2415
    2426
    2437
    2448
    2459
    2470
    2481
    2492
    2503
    2514
    2516
    2527
    2538
    2549
    2560
    2571
    2582
    2593
    2604
    2615
    2617
    2628
    2639
    2650
    2661
    2672
    2683
    2694
    2705
    2716
    2718
    2729
    2740
    2751
    2762
    2773
    2784
    2795
    2806
    2817
    2819
    2830
    2841
    2852
    2863
    2874
    2885
    2896
    2907
    2918
    2920
    2931
    2942
    2953
    2964
    2975
    2986
    2997
    3008
    3023
    3034
    3045
    3056
    3067
    3078
    3089
    3100
    3111
    3113
    3124
    3135
    3146
    3157
    3168
    3179
    3190
    3201
    3212
    3214
    3225
    3236
    3247
    3258
    3269
    3280
    3291
    3302
    3313
    3315
    3326
    3337
    3348
    3359
    3370
    3381
    3392
    3403
    3414
    3416
    3427
    3438
    3449
    3460
    3471
    3482
    3493
    3504
    3515
    3517
    3528
    3539
    3550
    3561
    3572
    3583
    3594
    3605
    3616
    3618
    3629
    3640
    3651
    3662
    3673
    3684
    3695
    3706
    3717
    3719
    3730
    3741
    3752
    3763
    3774
    3785
    3796
    3807
    3818
    3820
    3831
    3842
    3853
    3864
    3875
    3886
    3897
    3908
    3919
    3921
    3932
    3943
    3954
    3965
    3976
    3987
    3998
    4009
    4024
    4035
    4046
    4057
    4068
    4079
    4090
    4101
    4112
    4114
    4125
    4136
    4147
    4158
    4169
    4180
    4191
    4202
    4213
    4215
    4226
    4237
    4248
    4259
    4270
    4281
    4292
    4303
    4314
    4316
    4327
    4338
    4349
    4360
    4371
    4382
    4393
    4404
    4415
    4417
    4428
    4439
    4450
    4461
    4472
    4483
    4494
    4505
    4516
    4518
    4529
    4540
    4551
    4562
    4573
    4584
    4595
    4606
    4617
    4619
    4630
    4641
    4652
    4663
    4674
    4685
    4696
    4707
    4718
    4720
    4731
    4742
    4753
    4764
    4775
    4786
    4797
    4808
    4819
    4821
    4832
    4843
    4854
    4865
    4876
    4887
    4898
    4909
    4920
    4922
    4933
    4944
    4955
    4966
    4977
    4988
    4999
    5010
    5025
    5036
    5047
    5058
    5069
    5080
    5091
    5102
    5113
    5115
    5126
    5137
    5148
    5159
    5170
    5181
    5192
    5203
    5214
    5216
    5227
    5238
    5249
    5260
    5271
    5282
    5293
    5304
    5315
    5317
    5328
    5339
    5350
    5361
    5372
    5383
    5394
    5405
    5416
    5418
    5429
    5440
    5451
    5462
    5473
    5484
    5495
    5506
    5517
    5519
    5530
    5541
    5552
    5563
    5574
    5585
    5596
    5607
    5618
    5620
    5631
    5642
    5653
    5664
    5675
    5686
    5697
    5708
    5719
    5721
    5732
    5743
    5754
    5765
    5776
    5787
    5798
    5809
    5820
    5822
    5833
    5844
    5855
    5866
    5877
    5888
    5899
    5910
    5921
    5923
    5934
    5945
    5956
    5967
    5978
    5989
    6000
    6011
    6026
    6037
    6048
    6059
    6070
    6081
    6092
    6103
    6114
    6116
    6127
    6138
    6149
    6160
    6171
    6182
    6193
    6204
    6215
    6217
    6228
    6239
    6250
    6261
    6272
    6283
    6294
    6305
    6316
    6318
    6329
    6340
    6351
    6362
    6373
    6384
    6395
    6406
    6417
    6419
    6430
    6441
    6452
    6463
    6474
    6485
    6496
    6507
    6518
    6520
    6531
    6542
    6553
    6564
    6575
    6586
    6597
    6608
    6619
    6621
    6632
    6643
    6654
    6665
    6676
    6687
    6698
    6709
    6720
    6722
    6733
    6744
    6755
    6766
    6777
    6788
    6799
    6810
    6821
    6823
    6834
    6845
    6856
    6867
    6878
    6889
    6900
    6911
    6922
    6924
    6935
    6946
    6957
    6968
    6979
    6990
    7001
    7012
    7027
    7038
    7049
    7060
    7071
    7082
    7093
    7104
    7115
    7117
    7128
    7139
    7150
    7161
    7172
    7183
    7194
    7205
    7216
    7218
    7229
    7240
    7251
    7262
    7273
    7284
    7295
    7306
    7317
    7319
    7330
    7341
    7352
    7363
    7374
    7385
    7396
    7407
    7418
    7420
    7431
    7442
    7453
    7464
    7475
    7486
    7497
    7508
    7519
    7521
    7532
    7543
    7554
    7565
    7576
    7587
    7598
    7609
    7620
    7622
    7633
    7644
    7655
    7666
    7677
    7688
    7699
    7710
    7721
    7723
    7734
    7745
    7756
    7767
    7778
    7789
    7800
    7811
    7822
    7824
    7835
    7846
    7857
    7868
    7879
    7890
    7901
    7912
    7923
    7925
    7936
    7947
    7958
    7969
    7980
    7991
    8002
    8013
    8028
    8039
    8050
    8061
    8072
    8083
    8094
    8105
    8116
    8118
    8129
    8140
    8151
    8162
    8173
    8184
    8195
    8206
    8217
    8219
    8230
    8241
    8252
    8263
    8274
    8285
    8296
    8307
    8318
    8320
    8331
    8342
    8353
    8364
    8375
    8386
    8397
    8408
    8419
    8421
    8432
    8443
    8454
    8465
    8476
    8487
    8498
    8509
    8520
    8522
    8533
    8544
    8555
    8566
    8577
    8588
    8599
    8610
    8621
    8623
    8634
    8645
    8656
    8667
    8678
    8689
    8700
    8711
    8722
    8724
    8735
    8746
    8757
    8768
    8779
    8790
    8801
    8812
    8823
    8825
    8836
    8847
    8858
    8869
    8880
    8891
    8902
    8913
    8924
    8926
    8937
    8948
    8959
    8970
    8981
    8992
    9003
    9014
    9029
    9040
    9051
    9062
    9073
    9084
    9095
    9106
    9117
    9119
    9130
    9141
    9152
    9163
    9174
    9185
    9196
    9207
    9218
    9220
    9231
    9242
    9253
    9264
    9275
    9286
    9297
    9308
    9319
    9321
    9332
    9343
    9354
    9365
    9376
    9387
    9398
    9409
    9420
    9422
    9433
    9444
    9455
    9466
    9477
    9488
    9499
    9510
    9521
    9523
    9534
    9545
    9556
    9567
    9578
    9589
    9600
    9611
    9622
    9624
    9635
    9646
    9657
    9668
    9679
    9690
    9701
    9712
    9723
    9725
    9736
    9747
    9758
    9769
    9780
    9791
    9802
    9813
    9824
    9826
    9837
    9848
    9859
    9870
    9881
    9892
    9903
    9914
    9925
    9927
    9938
    9949
    9960
    9971
    9982
    9993