# 求给定数的位数if __name__=="__main__":print("请输入一个正整数n:", end="")
n =int(input())if n <=0:print("输出错误")
exit()
count =0# count存储数的位数while n !=0:
n = n //10
count +=1print(" %d 位数"%count)
%%time
# 自守数if __name__=="__main__":print("100000以内的自守数:")for number inrange(0,100000):
mul = number
k =1while(mul //10)>0:# 由number的位数确定截取数字进行乘法时的系数k
mul //=10
k *=10
a = k *10# a为截取部分积时的系数
mul =0# 积的最后n位
b =10# b为截取乘数相应位时的系数while k >0:# (部分积+截取被乘数的后N位*截取乘数的第M位),%a再截取部分积
mul =(mul +(number %(k *10))*(number % b - number %(b //10)))%a
k //=10# k为截取被乘数时的系数
b *=10if number == mul:# 判定若为自守数则输出print("%ld "%number, end="\t")print('\n')
100000以内的自守数:
0 1 5 6 25 76 376 625 9376 90625 CPU times: user 536 ms, sys: 2.14 ms, total: 539 ms
Wall time: 535 ms
论文:BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding 参考:BERT论文逐段精读、李沐精读系列、李宏毅版BERT讲解 一、介绍 BERT(Bidirectional EncoderRepresentation Transformer,双向Transformer编码器…