Algorithm/etc
자리수의 합
DingCoDing
2021. 12. 23. 17:22
반응형
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main() {
int n, sum=0, c=1, d=9, res=0;
scanf("%d", &n);
while(sum+d <n){
res = res+(c*d);
sum = sum+d;
c++;
d=d*10;
}
res += (n-sum)*c;
printf("%d",res);
}
자리수의 합 빠르게 구하기
반응형