1316(简单) self number

问题描述

1949年,印度数学家D.R. Kaprekar发现了一组名为“自我数字”的数字。对于任何正整数n,定义d(n)为n,加上n的数字的和(d代表数字,这是Kaprekar创造的术语)。
例如,d(75)= 75 + 7 + 5 = 87。给出任何正整数n作为起点,您可以构建无限增序列的整数n,d(n)、d(d(n))、d(d(d(n))),….
例如,如果你从33开始,下一个数字是33 + 3 + 3 = 39,下一个是39 + 3 + 9 = 51,下一个是51 + 5 + 1 = 57,所以你生成了序列

33、39、51、57、69、84、96、111、114、120、123、141、……

n被称为d(n)的生成器。在上面的序列中,33是一个39的生成器,39是一个51的生成器,51是一个57的生成器,等等。
一些数字有多个生成器:例如,101有两个生成器,91和100。一个没有生成器的数字是一个自数。
有13个自我数字小于100:1、3、5、7、9、20、31、42、53、64、75、86和97。

Write a program to output all positive self-numbers less than 10000 in increasing order, one per line

#include"stdio.h"
#define N 10001
int self[N];
int D();
int main()
{
    int i ;
    D();
    for(i = 1; i<=N; i++)
    {
        if(!self[i])
            printf("%d\n",i);
    }
    return 0;
}
int D()
{ 
    int sum;
    int i,j,flag;
    for(i = 1; i<=N; i++)
    {
        sum = i;
        flag = i;
        while(flag!=0)
        {
            j= flag%10;//j表示余数
            sum = sum+j;
            flag = flag/10;
        }
        self[sum] = 1;
    }
    return 1;
}
import sys from calculator import Ui_MainWindow from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * class calculator(QMainWindow, Ui_MainWindow): def __init__(self): super().__init__() self.setupUi(self) self.count = [] self.front = 0 self.double = 0 self.choice = '+' @pyqtSlot() def on_pushButton0_clicked(self): self.count.append(0) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton1_clicked(self): self.count.append(1) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton2_clicked(self): self.count.append(2) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton3_clicked(self): self.count.append(3) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton4_clicked(self): self.count.append(4) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton5_clicked(self): self.count.append(5) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton6_clicked(self): self.count.append(6) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton7_clicked(self): self.count.append(7) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton8_clicked(self): self.count.append(8) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) @pyqtSlot() def on_pushButton9_clicked(self): self.count.append(9) result = 0 for i in range(len(self.count)): result = pow(10, i) * int(self.count[-(i + 1)]) + result self.lcdNumber.display(int(result)) if __name__ == '__main__': app = QApplication(sys.argv) ui = calculator() ui.show() sys.exit(app.exec_())
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值