def P(x): y = reduce(lambda x, y: x * y, map(int, str(x))) return y and not x % y def Q(x): return P(x) and P(x + 1) print sum(Q(x) for x in xrange(2019))
11
12
13
14
reduce() 函数会对参数序列中元素进行累积。
reduce(function, iterable[, initializer])
1-8,除以本身
11能整除1 12能整除2
111和1111同理
1112整除2,1113整除3
1115整除5,1116整除6
1 2 3 4 5 6 7 8 11 111 1111 1112 1115共13个
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题