Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
【Problem Description】
Seeking Sn = a + aa + aaa + ... + aa ... an value of a, where a is a number. For example: 2 + 22 + 222 + 22222 + 2222 (where n = 5), n input from the keyboard.
[Input form]
And enter a positive integer n, a is a positive integer less than 10. Two numbers separated by a space.
[Form] output
Output Sn = a + aa + aaa + ... + aa ... an a value of a.
[Sample input]
2 5
[Sample output]
24690
[Sample Description]
2+22+222+2222+22222=24690
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a,n,b=0,c,Sn=0;
cin>>a>>n;
for(int i=1;i<=n;i++)
{
b=b+pow(10,i-1); //pow函数为次方(x,y)即x的y次方
c=b*a;
Sn=Sn+c;
}
cout<<Sn;
return 0;
}