#include // 以下,正の整数向け // verified with: yukicoder No.1128 Wedding Ceremony // int tmp, var = 0; を先に宣言する #define rd_int(var, tmp) \ for (;;) { \ tmp = getc_unlocked(stdin); \ if (tmp < '0' || tmp > '9') break; \ var = var * 10 + tmp - '0'; \ } // char buf[9]; int ptr = 0; を先に宣言する #define wt_int(var, buf, ptr) \ while (var) { \ buf[ptr++] = var % 10; \ var /= 10; \ } \ while (ptr--) putc_unlocked(buf[ptr] + '0', stdout); // 以下,負の数もOKなバージョン // verified with: yukicoder No.1132 凸凹 // int tmp, var = 0, sign = 0; を先に宣言する #define rd_int_s(var, tmp, sign) \ for (;;) { \ tmp = getchar_unlocked(); \ if (tmp == '-') { \ sign = 1; \ break; \ } else if ('0' <= tmp && tmp <= '9') { \ var = tmp - '0'; \ break; \ } \ } \ for (;;) { \ tmp = getc_unlocked(stdin); \ if (tmp < '0' || tmp > '9') break; \ var = var * 10 + tmp - '0'; \ } \ if (sign) var = -var; // char buf[9]; int ptr = 0, sign = 0; を先に宣言する #define wt_int_s(var, buf, ptr, sign) \ if (var < 0) { \ sign = 1; \ var = -var; \ } \ while (var) { \ buf[ptr++] = var % 10; \ var /= 10; \ } \ if (!ptr) buf[ptr++] = 0; \ if (sign) putc_unlocked('-', stdout); \ while (ptr--) putc_unlocked(buf[ptr] + '0', stdout); #define rd_int_s_(var, tmp, sign) \ var = sign = 0; \ rd_int_s(var, tmp, sign); #define wt_int_s_(var, buf, ptr, sign) \ ptr = sign = 0; \ wt_int_s(var, buf, ptr, sign); int main() { long long n = 0; int k, ptr = 0; char buf[20]; rd_int(n, k); if (n < 10) { putc_unlocked('0', stdout); return 0; } int ans = 0; while (n >= 10) { long long prod = 1; while (n > 0 && prod > 0) { prod *= (n % 10); n /= 10; } ans++; n = prod; } wt_int(ans, buf, ptr); return 0; }