#include<stdio.h>
int f(int n)
{
int i,j,count=0;
char str[100];
for(i=1;i<=n;i++){
sprintf(str,"%d",i);
for(j=0;str[j];j++){
if(str[j] == '1')
count++;
}
}
return count;
}
int main(void)
{
int num,ans;
puts("nの数は?");
scanf("&d",&num);
ans = f(num);
printf("ans=%d\n",ans);
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KCmludCBmKGludCBuKQp7CiAgICBpbnQgaSxqLGNvdW50PTA7CgljaGFyIHN0clsxMDBdOwoKCWZvcihpPTE7aTw9bjtpKyspewoJCXNwcmludGYoc3RyLCIlZCIsaSk7CgkJZm9yKGo9MDtzdHJbal07aisrKXsKCQkJaWYoc3RyW2pdID09ICcxJykKCQkJY291bnQrKzsKCQl9Cgl9CglyZXR1cm4gY291bnQ7Cn0KCmludCBtYWluKHZvaWQpCnsKCWludCBudW0sYW5zOwoJcHV0cygibuOBruaVsOOBr++8nyIpOwoJc2NhbmYoIiZkIiwmbnVtKTsKCQoJYW5zID0gZihudW0pOwoJcHJpbnRmKCJhbnM9JWRcbiIsYW5zKTsKCQoJcmV0dXJuIDA7Cn0=