| 模型 | 模型答案 | 正确答案 |
|---|---|---|
| 金声玉亮2.0 | ``` if i == l-1: if x % base == int(s): result += 1 return result return count(finish) - count(start-1) ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| deepseek-r1 | ```python else: prefix_part = x // (10 ** (n - l)) concatenated = prefix_part * (10 ** len(s)) + int(s) if concatenated <= x: result += 1 s_num = int(s) m = len(s) if m > n: return result if s_num <= x: result += 1 else: result -= 1 # Adjust if s_num >x but added in the loop if n > m: K = n - m -1 if K >=0: sum_middle = ( (limit +1) ** (K) ) -1 if K >=1 else 0 result += sum_middle return result return count(finish) - count(start -1) ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| gpto1 | ``` x_str = str(x) s_len = len(s) result = 0 max_len = len(x_str) min_len = len(str(start)) for L in range(s_len, max_len + 1): len_prefix = L - s_len # Build lower and upper bounds for this length low = max(start, 10**(L - 1)) high = min(x, 10**L - 1) if low > high: continue s_start = str(low).zfill(L) s_finish = str(high).zfill(L) memo = {} def dp(pos, tight_low, tight_high): if pos == L: return 1 key = (pos, tight_low, tight_high) if key in memo: return memo[key] if pos < len_prefix: min_digit = int(s_start[pos]) if tight_low else 0 max_digit = int(s_finish[pos]) if tight_high else limit total = 0 for d in range(min_digit, max_digit + 1): if d > limit: break next_tight_low = tight_low and (d == min_digit) next_tight_high = tight_high and (d == max_digit) total += dp(pos + 1, next_tight_low, next_tight_high) memo[key] = total return total else: # Suffix positions d = int(s[pos - len_prefix]) if d > limit: return 0 min_digit = int(s_start[pos]) if tight_low else 0 max_digit = int(s_finish[pos]) if tight_high else limit if d < min_digit or d > max_digit: return 0 next_tight_low = tight_low and (d == min_digit) next_tight_high = tight_high and (d == max_digit) total = dp(pos + 1, next_tight_low, next_tight_high) memo[key] = total return total result += dp(0, True, True) return result total = count(finish) - count(start - 1) return total ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| gpt-4o-2024-08-06 | ```python if curr < limit: break return result suffix = int(s) suffix_length = len(s) powerful_count = 0 # Calculate the number of powerful integers up to 'finish' powerful_count_finish = count(finish + 1) - count(suffix) # Calculate the number of powerful integers up to 'start - 1' powerful_count_start = count(start) - count(suffix) # The number of powerful integers in the range [start..finish] powerful_count = powerful_count_finish - powerful_count_start return powerful_count ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| Meta-Llama-3.1-405B-Instruct-Turbo | ```python if curr == 0: break if i == l-1: if x % (10**(len(s))) >= int(s): result += 1 x %= base if x == 0: break n -= 1 base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr, limit)-0+1)*cnt if curr > limit: break if curr == 0: break if i == l-1: if x % (10**(len(s))) >= int(s): result += 1 x %= base if x == 0: break return result return count(finish) - count(start-1) ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| Meta-Llama-3.1-70B-Instruct-Turbo | ```python if i == l-1: result += 1 if curr > limit: break return result return count(finish+1) - count(start) ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| DeepSeek-Coder-V2-Lite-Instruct | ```python if x % base == 0 and x // base == int(s): result += 1 return result result = 0 for x in range(start, finish + 1): result += count(x) return result ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| Qwen2-72B-Instruct | ```python else: result += cnt return result return count(finish) - count(start-1) ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| baichuan4 | ```python if l == 0: return 1 if l < 0: return 0 return cnt return count(finish) - count(start-1) ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| doubao | ```python while base > 0 and x % base == int(s): result += 1 base //= 10 return result count_start = count(start) count_finish = count(finish) return count_finish - count_start ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| gpto1 | ``` x_str = str(x) s_len = len(s) result = 0 max_len = len(x_str) min_len = len(str(start)) for L in range(s_len, max_len + 1): len_prefix = L - s_len # Build lower and upper bounds for this length low = max(start, 10**(L - 1)) high = min(x, 10**L - 1) if low > high: continue s_start = str(low).zfill(L) s_finish = str(high).zfill(L) memo = {} def dp(pos, tight_low, tight_high): if pos == L: return 1 key = (pos, tight_low, tight_high) if key in memo: return memo[key] if pos < len_prefix: min_digit = int(s_start[pos]) if tight_low else 0 max_digit = int(s_finish[pos]) if tight_high else limit total = 0 for d in range(min_digit, max_digit + 1): if d > limit: break next_tight_low = tight_low and (d == min_digit) next_tight_high = tight_high and (d == max_digit) total += dp(pos + 1, next_tight_low, next_tight_high) memo[key] = total return total else: # Suffix positions d = int(s[pos - len_prefix]) if d > limit: return 0 min_digit = int(s_start[pos]) if tight_low else 0 max_digit = int(s_finish[pos]) if tight_high else limit if d < min_digit or d > max_digit: return 0 next_tight_low = tight_low and (d == min_digit) next_tight_high = tight_high and (d == max_digit) total = dp(pos + 1, next_tight_low, next_tight_high) memo[key] = total return total result += dp(0, True, True) return result total = count(finish) - count(start - 1) return total ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| kimi | ```python result += min(x%base-int(s)+1, limit+1)*cnt return result s = int(s) if s > limit or s > finish: return 0 result = 0 for i in range(1, limit+1): if (start-i*s)%s == 0 and (start-i*s)//s <= finish//s: result += count((start-i*s)//s) if (finish-i*s)%s == 0 and (finish-i*s)//s >= start//s: result -= count((finish-i*s)//s) return result ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| minimax | ```python class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n - len(s) cnt = (limit + 1)**l for i in range(l): base //= 10 curr = x // base % 10 cnt //= limit + 1 result += (min(curr - 1, limit) - 0 + 1) * cnt if curr > limit: break return result powerful_count = 0 for x in range(start, finish + 1): if s == str(x)[-len(s):]: powerful_count += count(x) return powerful_count ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| wenxinyiyan | ```python if l > 0: x %= base if x > int(s) - 1: result += cnt elif x == int(s) - 1: result += (limit+1)**(l-1) for i in range(n-l-1, -1, -1): base //= 10 curr = x//base%10 if curr > int(s[i]): result += (limit - int(s[i])) * (limit+1)**(n-i-1) elif curr < int(s[i]): break return result if start > finish: return 0 if s == "0": if start == 0: return 1 return 0 return count(finish) - count(start-1) ``` This solution defines a helper function `count(x)` to count the number of powerful integers less than or equal to `x`. It first calculates the length `n` of `x` and initializes some variables. Then, it iterates over the digits of `x` from the most significant digit to the least significant digit, comparing them with the corresponding digits of `s`. Based on the comparison, it updates the count of powerful integers. Finally, the main function `numberOfPowerfulInt` checks some base cases and returns the difference between the count of powerful integers less than or equal to `finish` and the count of powerful integers less than `start`. This gives the total number of powerful integers in the range `[start..finish]`. |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| zhipu | ``` else: result += cnt return result return count(finish) - count(start - 1) ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |
| deepseek-v3 | ```python else: last_part = x % (10 ** len(s)) if last_part >= int(s): result += 1 return result return count(finish) - count(start - 1) ``` |
class Solution(object): def numberOfPowerfulInt(self, start, finish, limit, s): """ :type start: int :type finish: int :type limit: int :type s: str :rtype: int """ def count(x): def length(x): result = 0 while x: x //= 10 result += 1 return result result = 0 n = length(x) base = 10**n l = n-len(s) cnt = (limit+1)**l for i in range(l): base //= 10 curr = x//base%10 cnt //= limit+1 result += (min(curr-1, limit)-0+1)*cnt if curr > limit: break else: if x%base >= int(s): result += 1 return result return count(finish)-count(start-1) |