给定两个均不超过9的正整数a和n,要求编写程序求a+aa+aaa++⋯+aa⋯a(n个a)之和。
输入格式:
输入在一行中给出不超过9的正整数a和n。
输出格式:
在一行中按照“s = 对应的和”的格式输出。
输入样例:
2 3
输出样例:
s = 246
a,n=map(int,input().split())
time=0
sum=0
t=a
while time<n:
sum+= t
t=t*10+a
time+=1 #没有++time 或者time++
print("s = %d"%sum)
# map()的使用
# https://www.php.cn/python-tutorials-424888.html
本文介绍了一个简单的编程问题:计算形如a+aa+aaa+...的累加序列,并提供了一个Python实现示例。
989

被折叠的 条评论
为什么被折叠?



