solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define sz(a) (ll)a.size()
#define lli long long int
#define pb push_back
#define pf push_front
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
#define M 1000000007
#define pi 3.1415926535
//nck use fermit theorem mod inverse a-1%p=(a pow p-2)%p
//vector<ll> g[]
//vector<bool> vis()
//set lower bound set_name.lower_boubnd(key)
ll dp[10][200001];
int main(){
fast;
ll t;
cin>>t;
for(int i=0;i<10;i++){
dp[i][0]=1;
}
for(int i=1;i<=200000;i++){
for(int j=0;j<9;j++){
dp[j][i]=dp[j+1][i-1]%M;
}
dp[9][i]=(dp[0][i-1]+dp[1][i-1])%M;
}
while(t--){
ll n,m;
string s;
cin>>s>>m;
ll ans=0;
for(auto x:s){
ans+=dp[x-'0'][m];
ans=ans%M;
}
cout<<ans<<"\n";
}
return 0;
}
| 9 |
CPP
|
import sys,os,io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
maxn = 2*10**5 + 15
dp = [0]*(maxn)
dp[0]=1
mod = 10**9 + 7
for i in range (maxn-13):
dp[i]%=mod
if i>=10:
dp[i+9] += dp[i]
dp[i+10] += dp[i]
for i in range (1,maxn):
dp[i]+=dp[i-1]
# print(dp[:30])
for _ in range (int(input())):
n,m = [int(i) for i in input().split()]
a = [int(i) for i in str(n)]
cnt = 0
ans = 0
for i in range (len(a)):
ans += dp[m+a[i]]
ans %= mod
print(ans)
| 9 |
PYTHON3
|
#include <iostream>
#include <vector>
#include <map>
using namespace std;
const int MAX_N = 2e5 + 5, MOD = 1e9 + 7;
int length[MAX_N];
void precompute()
{
for(int i = 0; i <= 8; i++)
{
length[i] = 2;
}
length[9] = 3;
for(int i = 10; i < MAX_N; i++)
{
length[i] = (length[i - 9] + length[i - 10])%MOD;
}
}
void solve()
{
int n, no_of_operations;
cin >> n >> no_of_operations;
long long answer = 0;
while(n > 0)
{
int digit = n%10;
long long this_length = (no_of_operations < 10 - digit ? 1 : length[no_of_operations - (10 - digit)]);
//cout << "D = " << digit << " this = " << this_length << "\n";
n /= 10;
answer = (answer + this_length)%MOD;
}
cout << answer << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
precompute();
int no_of_test_cases;
cin >> no_of_test_cases;
while(no_of_test_cases--)
solve();
return 0;
}
| 9 |
CPP
|
from sys import stdin
input = stdin.readline
mxn = 2 * (10 ** 5) + 10
mod = 10 ** 9 + 7
dp = [1] * mxn
for i in range(10, mxn):
dp[i] = (dp[i - 9] + dp[i - 10]) % mod
for test in range(int(input())):
n, k = map(int, input().strip().split())
ans = 0
while n:
ans = (ans + dp[k + n % 10]) % mod
n //= 10
print(ans)
| 9 |
PYTHON3
|
// amit
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL);
#define ll long long int
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pi pair<ll,ll>
#define pb push_back
ll dp[200022]={1,1,1,1,1,1,1,1,1,1};
void fun()
{
for(int i=10;i<200022;i++)
dp[i]=(dp[i-10]+dp[i-9])%1000000007;
}
int main()
{
fast;
int t;cin>>t;
fun();
while(t--)
{
ll n,m;cin>>n>>m;
ll ans=0;
while(n)
{
ans=(ans+dp[m+(n%10)])%1000000007;
n/=10;
}
cout<<ans<<'\n';
}
return 0;
}
| 9 |
CPP
|
/** D Bag*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fr(iter,n) for(ll iter=0;iter<n;++iter)
#define forr(iter,s,e) for(ll iter=s;iter<e;++iter)
#define ufr(iter,s,e) for(ll iter=s;iter>=e;--iter)
#define MOD (ll)1000000007
#define pii pair<ll,ll>
#define vi vector<ll>
#define vd vector<double>
#define vpi vector<pii>
#define vs vector<string>
#define pb push_back
#define pob pop_back
#define ub upper_bound
#define lb lower_bound
#define eb emplace_back
#define pf push_front
#define pof pop_front
#define mp(x,y) make_pair(x,y)
#define all(a) a.begin(),a.end()
#define ff first
#define ss second
#define lcm(a,b) (a*b)/__gcd(a,b)
#define mem(a,val) memset(a,val,sizeof(a))
#define trace1(x) cerr<<#x<<": "<<x<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f, g) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<" | "<<#g<<": "<<g<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cerr<<*it<<" ";cerr<<endl;
#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);
#define piii pair< ll, pair<ll, ll > >
ll power(ll a, ll b, ll p){
ll res = 1;
a = a%p;
while(b > 0){
if(b&1){
res = ((res%p) * (a%p))%p;
}
b /= 2;
a = ((a%p)*(a%p))%p;
}
return res;
}
ll fact[200005];
ll ncr(ll a, ll b){
if(a < b){
return 0LL;
}
if(a == b){
return 1LL;
}
ll ans = fact[a];
ll den = (fact[b]*fact[a - b])%MOD;
den = (power(den, MOD - 2, MOD));
ans = (ans * den)%MOD;
return ans;
// ll ans = 1;
// ll cnt = 1;
// for(ll i = a - b + 1; i <= a; i ++){
// ans *= i;
// ans /= cnt;
// cnt ++;
// }
// return ans;
}
void add(vi& a, vi& b){
// a = a + b
fr(i, a.size()){
a[i] = (a[i] + b[i])%MOD;
}
return;
}
inline void do_op(vector<vi>& dp, vi& cnt){
vi new_cnt(11);
for(ll i = 1; i <= 10; i ++){
for(ll j = 1; j <= 10; j ++){
new_cnt[i] = (new_cnt[i] + dp[i][j]*cnt[j])%MOD;
}
}
cnt = new_cnt;
}
inline void op_10_5(vi &cnt){
vector<vi> dp(11);
// Hard code
dp[1] = {0, 651904299, 285978270, 759489075, 969290391, 521867181, 810068539, 294376709, 604618109, 408984056, 641652427};
dp[2] = {0, 50636476, 651904299, 285978270, 759489075, 969290391, 521867181, 810068539, 294376709, 604618109, 408984056};
dp[3] = {0, 13602158, 50636476, 651904299, 285978270, 759489075, 969290391, 521867181, 810068539, 294376709, 604618109};
dp[4] = {0, 898994818, 13602158, 50636476, 651904299, 285978270, 759489075, 969290391, 521867181, 810068539, 294376709};
dp[5] = {0, 104445241, 898994818, 13602158, 50636476, 651904299, 285978270, 759489075, 969290391, 521867181, 810068539};
dp[6] = {0, 331935713, 104445241, 898994818, 13602158, 50636476, 651904299, 285978270, 759489075, 969290391, 521867181};
dp[7] = {0, 491157565, 331935713, 104445241, 898994818, 13602158, 50636476, 651904299, 285978270, 759489075, 969290391};
dp[8] = {0, 728779459, 491157565, 331935713, 104445241, 898994818, 13602158, 50636476, 651904299, 285978270, 759489075};
dp[9] = {0, 45467338, 728779459, 491157565, 331935713, 104445241, 898994818, 13602158, 50636476, 651904299, 285978270};
dp[10] = {0, 285978270, 759489075, 969290391, 521867181, 810068539, 294376709, 604618109, 408984056, 641652427, 10251872};
do_op(dp, cnt);
return;
}
inline void op_10_4(vi &cnt){
vector<vi> dp(11);
// Hard code
dp[1] = {0, 700725413, 513422121, 202657640, 646409750, 70321224, 933251429, 490798159, 929577963, 6573970, 149613446};
dp[2] = {0, 156187416, 700725413, 513422121, 202657640, 646409750, 70321224, 933251429, 490798159, 929577963, 6573970};
dp[3] = {0, 936151933, 156187416, 700725413, 513422121, 202657640, 646409750, 70321224, 933251429, 490798159, 929577963};
dp[4] = {0, 420376115, 936151933, 156187416, 700725413, 513422121, 202657640, 646409750, 70321224, 933251429, 490798159};
dp[5] = {0, 424049581, 420376115, 936151933, 156187416, 700725413, 513422121, 202657640, 646409750, 70321224, 933251429};
dp[6] = {0, 3572646, 424049581, 420376115, 936151933, 156187416, 700725413, 513422121, 202657640, 646409750, 70321224};
dp[7] = {0, 716730974, 3572646, 424049581, 420376115, 936151933, 156187416, 700725413, 513422121, 202657640, 646409750};
dp[8] = {0, 849067390, 716730974, 3572646, 424049581, 420376115, 936151933, 156187416, 700725413, 513422121, 202657640};
dp[9] = {0, 716079761, 849067390, 716730974, 3572646, 424049581, 420376115, 936151933, 156187416, 700725413, 513422121};
dp[10] = {0, 513422121, 202657640, 646409750, 70321224, 933251429, 490798159, 929577963, 6573970, 149613446, 551111967};
do_op(dp, cnt);
return;
}
inline void op_10_3(vi &cnt){
vector<vi> dp(11);
// Hard code
dp[1] = {0, 206671027, 618188410, 427909462, 149392123, 964816865, 37540036, 142216143, 257687866, 485793807, 129104111};
dp[2] = {0, 614897918, 206671027, 618188410, 427909462, 149392123, 964816865, 37540036, 142216143, 257687866, 485793807};
dp[3] = {0, 743481673, 614897918, 206671027, 618188410, 427909462, 149392123, 964816865, 37540036, 142216143, 257687866};
dp[4] = {0, 399904009, 743481673, 614897918, 206671027, 618188410, 427909462, 149392123, 964816865, 37540036, 142216143};
dp[5] = {0, 179756179, 399904009, 743481673, 614897918, 206671027, 618188410, 427909462, 149392123, 964816865, 37540036};
dp[6] = {0, 2356894, 179756179, 399904009, 743481673, 614897918, 206671027, 618188410, 427909462, 149392123, 964816865};
dp[7] = {0, 114208981, 2356894, 179756179, 399904009, 743481673, 614897918, 206671027, 618188410, 427909462, 149392123};
dp[8] = {0, 577301585, 114208981, 2356894, 179756179, 399904009, 743481673, 614897918, 206671027, 618188410, 427909462};
dp[9] = {0, 46097865, 577301585, 114208981, 2356894, 179756179, 399904009, 743481673, 614897918, 206671027, 618188410};
dp[10] = {0, 618188410, 427909462, 149392123, 964816865, 37540036, 142216143, 257687866, 485793807, 129104111, 77566916};
do_op(dp, cnt);
return;
}
inline void op_10_2(vi &cnt){
vector<vi> dp(11);
// Hard code
dp[1] = {0, 12, 11, 45, 120, 210, 252, 210, 120, 45, 10};
dp[2] = {0, 55, 12, 11, 45, 120, 210, 252, 210, 120, 45};
dp[3] = {0, 165, 55, 12, 11, 45, 120, 210, 252, 210, 120};
dp[4] = {0, 330, 165, 55, 12, 11, 45, 120, 210, 252, 210};
dp[5] = {0, 462, 330, 165, 55, 12, 11, 45, 120, 210, 252};
dp[6] = {0, 462, 462, 330, 165, 55, 12, 11, 45, 120, 210};
dp[7] = {0, 330, 462, 462, 330, 165, 55, 12, 11, 45, 120};
dp[8] = {0, 165, 330, 462, 462, 330, 165, 55, 12, 11, 45};
dp[9] = {0, 56, 165, 330, 462, 462, 330, 165, 55, 12, 11};
dp[10] = {0, 11, 45, 120, 210, 252, 210, 120, 45, 10, 2};
do_op(dp, cnt);
return;
}
inline void op_10(vi &cnt){
vi new_cnt;
new_cnt = cnt;
for(ll j = 1; j <= 10; j ++){
if(j == 9){
new_cnt[j] = (new_cnt[j] + cnt[1] + cnt[j + 1])%MOD;
}else if(j == 10){
new_cnt[j] = (new_cnt[j] + cnt[1])%MOD;
}else{
new_cnt[j] = (new_cnt[j] + cnt[j + 1]);
}
}
cnt = new_cnt;
}
inline void op_1(vi &cnt){
vi new_cnt(11);
for(ll j = 1; j <= 10; j ++){
if(j == 1){
new_cnt[10] = (new_cnt[10] + cnt[j])%MOD;
new_cnt[9] = (new_cnt[9] + cnt[j])%MOD;
}else{
new_cnt[j - 1] = (new_cnt[j - 1] + cnt[j])%MOD;
}
}
cnt = new_cnt;
}
void solve()
{
ll n, m;
cin >> n >> m;
vi cnt(11);
ll sz = 0, nn = n;
while(nn){
ll digit = nn%10;
sz ++;
cnt[10 - digit] ++;
nn /= 10;
}
ll pw = 5LL;
while(pw >= 0){
ll div = (ll)powl(10, pw);
ll times = m/div;
while(times--){
switch(pw) {
case 5LL :
op_10_5(cnt);
break; //optional
case 4LL :
op_10_4(cnt);
break; //optional
case 3LL :
op_10_3(cnt);
break; //optional
case 2LL :
op_10_2(cnt);
break; //optional
case 1LL :
op_10(cnt);
break; //optional
case 0LL :
op_1(cnt);
break; //optional
// you can have any number of case statements.
default : //Optional
break;
}
}
m %= div;
pw --;
}
ll sum = 0;
fr(i, 11){
sum = (sum + cnt[i])%MOD;
}
cout << sum << "\n";
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ll mx = (ll)2e5 + 5LL;
vector< vi > dp(11, vi(mx));
vi cnt(11);
cnt[1] = 1;
dp[1][0] = 1;
fr(i, mx - 1){
op_1(cnt);
fr(j, 11){
dp[1][i + 1] += cnt[j];
dp[1][i + 1] %= MOD;
}
}
forr(i, 2, 11){
dp[i][0] = 1;
forr(j, 1, mx){
dp[i][j] = dp[i - 1][j - 1];
}
}
// forr(i, 1, 11){
// cerr << i << " => ";
// fr(j, 25){
// cerr << dp[i][j] << " ";
// }
// cerr << "\n";
// }
// fact[0] = 1;
// for(ll i = 1; i < 200005; i ++){
// fact[i] = (fact[i - 1]* i)% MOD;
// }
zoom;
int t;
cin>>t;
// t=1;
fr(t1,t)
{
// cout<<"Case #"<<t1+1<<": ";
// solve();
ll n, m;
cin >> n >> m;
string s = to_string(n);
// trace2(s, m);
ll sum = 0;
fr(i, s.size()){
sum = (sum + dp[10 - (ll)(s[i] - '0')][m])%MOD;
}
cout << sum << "\n";
// // cout<<'\n';
}
return 0;
}
| 9 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << " " << H; dbg_out(T...); }
#ifdef SMIE
#define debug(args...) cerr << "(" << #args << "):", dbg_out(args)
#else
#define debug(args...)
#endif
const int mxm = 2e5 + 20;
const int MOD = 1e9 + 7;
int one[mxm], zero[mxm], dp[mxm];
int main() {
ios_base::sync_with_stdio(false); //DON'T mix C and C++ I/O
//cin.tie(NULL); //DON'T use for interactive problem
dp[0] = 1, zero[0] = 1;
for (int i = 1; i < mxm; i++) {
if (i >= 10) {
one[i] += zero[i - 10];
one[i] %= MOD;
zero[i] += zero[i - 10];
zero[i] %= MOD;
}
if (i >= 9) {
one[i] += one[i - 9];
one[i] %= MOD;
zero[i] += one[i - 9];
zero[i] %= MOD;
}
dp[i] = (dp[i - 1] + one[i]) % MOD;
}
int tests = 1, testno = 0;
cin >> tests;
while (tests--) {
int n, m;
cin >> n >> m;
int ans = 0;
while (n > 0) {
ans = (ans + dp[n % 10 + m]) % MOD;
n /= 10;
}
cout << ans << '\n';
}
}
| 9 |
CPP
|
#include<bits/stdc++.h>
using namespace std;
#define d1(a) {cout<<#a<<"="<<(a)<<'\n';}
#define d2(a,b) {cout<<#a<<"="<<(a)<<" "<<#b<<"="<<(b)<<'\n';}
#define d3(a,b,c) {cout<<#a<<"="<<(a)<<" "<<#b<<"="<<(b)<<" "<<#c<<"="<<(c)<<'\n';}
#define D1(a) {cout<<#a<<"里的元素为 ";for(auto x:a)cout<<x<<' ';cout<<'\n';}
#define D2(a) {cout<<#a<<"里的元素为 ";for(auto [x,y]:a)cout<<x<<' '<<y<<" ";cout<<'\n';}
#define D3(a) {cout<<#a<<"里的元素为 ";for(auto [x,y,z]:a)cout<<x<<' '<<y<<' '<<z<<" ";cout<<'\n';}
const int N=2e5+5,mod=1e9+7;
vector<vector<long long> >dp(10,vector<long long>(N));
void solve(){
int n,m;cin>>n>>m;
long long ans=0;
for(auto x:to_string(n))
ans=(ans+dp[x-'0'][m])%mod;
cout<<ans<<'\n';
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
for(int i=0;i<N;i++)
for(int j=0;j<10;j++)
dp[j][i]=(i+j<10?1:(dp[1][i+j-10]+dp[0][i+j-10]))%mod;
int t;cin>>t;
while(t--)
solve();
return 0;
}
| 9 |
CPP
|
#pyrival orz
import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
############ ---- Dijkstra with path ---- ############
def dijkstra(start, distance, path, n):
# requires n == number of vertices in graph,
# adj == adjacency list with weight of graph
visited = [False for _ in range(n)] # To keep track of vertices that are visited
distance[start] = 0 # distance of start node from itself is 0
for i in range(n):
v = -1 # Initialize v == vertex from which its neighboring vertices' distance will be calculated
for j in range(n):
# If it has not been visited and has the lowest distance from start
if not visited[v] and (v == -1 or distance[j] < distance[v]):
v = j
if distance[v] == math.inf:
break
visited[v] = True # Mark as visited
for edge in adj[v]:
destination = edge[0] # Neighbor of the vertex
weight = edge[1] # Its corresponding weight
if distance[v] + weight < distance[destination]: # If its distance is less than the stored distance
distance[destination] = distance[v] + weight # Update the distance
path[destination] = v # Update the path
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a%b)
def lcm(a, b):
return (a*b)//gcd(a, b)
def ncr(n, r):
return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
def npr(n, r):
return math.factorial(n)//math.factorial(n-r)
def seive(n):
primes = [True]*(n+1)
ans = []
for i in range(2, n):
if not primes[i]:
continue
j = 2*i
while j <= n:
primes[j] = False
j += i
for p in range(2, n+1):
if primes[p]:
ans += [p]
return ans
def factors(n):
factors = []
x = 1
while x*x <= n:
if n % x == 0:
if n // x == x:
factors.append(x)
else:
factors.append(x)
factors.append(n//x)
x += 1
return factors
# Functions: list of factors, seive of primes, gcd of two numbers,
# lcm of two numbers, npr, ncr
def main():
try:
max_n = 2*10**5
mod = 10**9 + 7
dp = [0]*max_n
for i in range(0, 9):
dp[i] = 2
dp[9] = 3
for i in range(10, 2*10**5):
dp[i] = dp[i-9] + dp[i-10]
dp[i] %= mod
for _ in range(inp()):
n, m = invr()
ans = 0
while n > 0:
x = n%10
ans += 1*int(m + x < 10) + dp[m+x-10]*int(not m + x < 10)
ans %= mod
n //= 10
print(ans)
except Exception as e:
print(e)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
| 9 |
PYTHON3
|
from sys import stdin
t=int(stdin.readline())
mod=10**9+7
f=[0]*(2*10**5+10)
for i in range(10):
f[i]=1
f[10]=2
for i in range(11,2*10**5+10):
f[i]=(f[i-10]+f[i-9])%mod
for _ in range(t):
n,m=map(int,stdin.readline().split())
c=[0]*10
n=str(n)
for i in range(len(n)):
c[int(n[i])]+=1
ans=0
for i in range(10):
ans+=c[i]*f[m+i]
ans%=mod
print(ans)
| 9 |
PYTHON3
|
// MD. Ashiqur Rahman
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define scn(x) scanf("%d",&x)
#define scnl(x) scanf("%lld",&x)
#define prnt(x) printf("%d\n",x)
#define prntl(x) printf("%lld\n",x)
#define prii pair<int,int>
#define mapii map<int,int>
#define mapll map<ll,ll>
#define mapci map<char,int>
#define mapcl map<char,ll>
#define mapsi map<string,int>
#define mapsl map<string,ll>
#define prll pair<ll,ll>
#define vctri vector<int>
#define vctrl vector<ll>
#define vctrd vector<double,double>
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define F first
#define S second
#define mp make_pair
#define ftc(x) cerr << #x << ": " << x << " " << '\n';
#define PI acos(-1)
#define lcm(a,b) ((a*b)/__gcd(a,b))
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sqr(a) ((a)*(a))
#define memset(x,v) memset(x, v, sizeof(x))
#define ask '\n'
#define negmod(x,y) ((x % y) + y) % y
ll MOD;
inline void modulas(ll a) {MOD = a;}
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
vector<bool> isPrime(10000010, true);
inline void seivePrime(ll L, ll R) { ll lim = sqrt(R);for (ll i = 2; i <= lim; ++i){
for (ll j = max(i * i, (L + i - 1) / i * i); j <= R; j += i)
isPrime[j - L] = false;}if (L == 1)isPrime[0] = false;}
inline ll chckPrime(ll L,ll prme){return isPrime[prme - L];}
inline ll cntPrime(ll L,ll R){return count(isPrime.begin(),isPrime.begin() + R - L + 1,true);}
ll prclc[200010][15];
void pre(){
ll clc[15];
for(char a = '0';a <= '9';a ++){
memset(clc,0);
clc[a - '0'] = 1;
ll sol = 1;
for(int i = 1;i <= 200005;i ++){
int tmp = 0;
if(clc[9]){
sol = modAdd(sol,clc[9]);
tmp = clc[9];
clc[9] = 0;
}
for(int j = 8;j >= 0;j --){
if(clc[j]){
clc[j + 1] = clc[j];
clc[j] = 0;
}
}
clc[1] = modAdd(clc[1],tmp);
clc[0] = tmp;
prclc[i][a - '0'] = sol;
}
}
}
int main(){
fast;
int t = 1;
cin >> t;
modulas(1000000007);
pre();
while(t --){
ll n,m;
cin >> n >> m;
string s = to_string(n);
ll sol = 0;
for(int i = 0;i < s.size();i ++)
sol = modAdd(sol,prclc[m][s[i] - '0']);
cout << sol << "\n";
}
return 0;
}
| 9 |
CPP
|
import sys
input = sys.stdin.readline
t = int(input())
mod = pow(10, 9) + 7
cnt = [0 for _ in range(200020)]
cnt0 = [0] * 10
cnt0[0] = 1
s = 1
for k in range(200020):
x = cnt0[(9 - k) % 10]
cnt0[(10 - k) % 10] += x
cnt0[(10 - k) % 10] %= mod
s += x
s %= mod
cnt[k] = s
for _ in range(t):
n, m = map(int, input().split())
ans = 0
for i in str(n):
ans += cnt[m + int(i) - 1]
ans %= mod
print(ans)
| 9 |
PYTHON3
|
#include <iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<stdio.h>
using namespace std;
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
//#define mp make_pair
#define mt make_tuple
#define popb pop_back
#define popf pop_front
#define int long long int
#define PI 3.1415926535897932
#define all(v) v.begin(),v.end()
//#define endl "\n"
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lop(i,a,b) for(int i=a;i>=b;i--)
#define prec(x) cout<<fixed<<setprecision(x)
#define toup(su) transform(su.begin(), su.end(), su.begin(), ::toupper);
#define tolow(su) transform(su.begin(), su.end(), su.begin(), ::tolower);
//if(concated.find(s2)!=string::npos)
int M=1000000007;
int dp[2][200005];
int gcd(int a, int b)
{
return (b==0)?a:gcd(b,a%b);
}
int lcm(int a, int b)
{
int l= (a*b);
l=l/gcd(a,b);
return l;
}
int po(int a, int b)
{
if(b==0) return 1;
int temp=po(a,b/2);
int z=( (temp%M) * (temp%M))%M;
if(b%2)
return ((z%M) * (a%M))%M;
else
return z%M;
}
signed main()
{
fast
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t=1;
cin>>t;
//int prime[1000001]={0};
int xx=1;
rep(j,0,200005)
{
rep(i,0,2)
{
if(i==0 && j<10) dp[i][j]=1;
else if(i==1 && j<9) dp[i][j]=1;
else if(i==0)
{
dp[i][j] = ( (dp[0][j-10]%M) + (dp[1][j-10] %M) )%M;
}
else if(i==1)
{
dp[i][j] = ( (dp[0][j-9]%M) + (dp[1][j-9] %M) )%M;
}
}
}
while(t--)
{
int n,m; cin>>n>>m;
vector<int> v;
while(n)
{
v.pb(n%10);
n/=10;
}
int ans=0;
for(auto i:v)
{
int p=i;
if(10-p<=m)
{
ans=(ans%M + (dp[0][m-(10-p)] )%M+ (dp[1][m-(10-p)])%M )%M;
}
else
{
ans= (ans%M + 1)%M;
}
}
cout<<ans<<endl;
//xx++;
}
return 0;
}
| 9 |
CPP
|
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200011; //check the limits, dummy
struct mi {
ll v; explicit operator ll() const { return v; }
mi() { v = 0; }
mi(ll _v) {
v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
if (v < 0) v += MOD;
}
friend bool operator==(const mi& a, const mi& b) {
return a.v == b.v; }
friend bool operator!=(const mi& a, const mi& b) {
return !(a == b); }
friend bool operator<(const mi& a, const mi& b) {
return a.v < b.v; }
mi& operator+=(const mi& m) {
if ((v += m.v) >= MOD) v -= MOD;
return *this; }
mi& operator-=(const mi& m) {
if ((v -= m.v) < 0) v += MOD;
return *this; }
mi& operator*=(const mi& m) {
v = v*m.v%MOD; return *this; }
mi& operator/=(const mi& m) { return (*this) *= inv(m); }
friend mi pow(mi a, ll p) {
mi ans = 1; assert(p >= 0);
for (; p; p /= 2, a *= a) if (p&1) ans *= a;
return ans;
}
friend mi inv(const mi& a) { assert(a.v != 0);
return pow(a,MOD-2); }
mi operator-() const { return mi(-v); }
mi& operator++() { return *this += 1; }
mi& operator--() { return *this -= 1; }
mi operator++(int) { mi temp; temp.v = v++; return temp; }
mi operator--(int) { mi temp; temp.v = v--; return temp; }
friend mi operator+(mi a, const mi& b) { return a += b; }
friend mi operator-(mi a, const mi& b) { return a -= b; }
friend mi operator*(mi a, const mi& b) { return a *= b; }
friend mi operator/(mi a, const mi& b) { return a /= b; }
friend ostream& operator<<(ostream& os, const mi& m) {
os << m.v; return os;
}
friend istream& operator>>(istream& is, mi& m) {
ll x; is >> x;
m.v = x;
return is;
}
};
typedef vector<mi> vmi;
typedef pair<mi,mi> pmi;
typedef vector<pmi> vpmi;
mi ans[10][MX];
void solve() {
mi res = 0;
string S; cin >> S;
int M; cin >> M;
trav(a, S) {
res += ans[a-'0'][M];
}
cout << res << nl;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
F0R(x, 10) {
mi cnt[10];
cnt[x] = 1;
F0R(it, MX-1) {
mi nxt[10];
F0R(i, 9) {
nxt[i+1] += cnt[i];
}
nxt[0] += cnt[9]; nxt[1] += cnt[9];
F0R(i, 10) cnt[i] = nxt[i];
F0R(i, 10) ans[x][it+1] += cnt[i];
}
}
int T = 1;
cin >> T;
while(T--) {
solve();
}
return 0;
}
// read the question correctly (ll vs int)
// template by bqi343
| 9 |
CPP
|
//go to line 54 for some useful code.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.hpp"
#else
#define dbg(...) 47
#define dbgm(...) 47
#endif
// refer https://codeforces.com/blog/entry/66279
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
//refer-> https://codeforces.com/blog/entry/62393
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
typedef long long ll;
typedef unsigned long int ul;
typedef unsigned long long int ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> matrix;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef unordered_map<int,int, custom_hash> umap;
typedef unordered_set<int, custom_hash>uset;
#define f(i, x, n) for (int i = x; i < n; i++)
#define rf(i, n, x) for(int i=n;i>=x;--i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mem(a, b) memset(a, b, sizeof(a))
#define fast_io() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define oo INT64_MAX
ll const mran = 2e5+10;
ll const mod = 1e9+7;
// write your code here....
ll dp[mran][10];
void inline add(ll &a, ll b){
a+=b;
a%=mod;
}
void pre(){
f(j, 0, 10)dp[0][j] =1;
f(i, 1, mran){
f(j, 0, 10){
if(j<9) dp[i][j] = dp[i-1][j+1];
else dp[i][j] = (dp[i-1][1]+dp[i-1][0])%mod;
}
}
}
void solve(){
int n, m;
cin>>n>>m;
ll ans =0;
while(n>0){
int x = n%10;
add(ans, dp[m][x]);
n/=10;
}
cout<<ans<<endl;
}
int main()
{
fast_io();
cerr << "...............Console is yours! :)................." << endl;
int T;
cin>>T;
int O = T;
pre();
while(T--){
solve();
}
cerr<<".......^_^........."<<endl;
return 0;
}
| 9 |
CPP
|
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define precision cout << fixed << setprecision(15);
const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
clock_t time_p = clock();
void ktj() {
time_p = clock() - time_p;
cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}
inline int add(int a, int b){
a %= mod; b %= mod;
a += b;
if(a >= mod) a -= mod;
return a;
}
inline int sub(int a, int b){
a %= mod; b %= mod;
a -= b;
if(a < 0) a += mod;
return a;
}
inline int mul(int a, int b){
int64_t c = (int64_t)a * (int64_t)b;
c %= mod;
return (int)(c);
}
inline int power(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1) {
res = mul(res, a);
}
a = mul(a, a);
b >>= 1;
}
return res;
}
inline int inv(int a) {
a %= mod;
if (a < 0) a += mod;
int b = mod, u = 0, v = 1;
while (a) {
int t = b / a;
b -= t * a; swap(a, b);
u -= t * v; swap(u, v);
}
assert(b == 1);
if (u < 0) u += mod;
return u;
}
const int N = 2e5 + 5;
int dp[N];
void pre() {
for (int i = 0; i < 9; i++)
dp[i] = 2;
dp[9] = 3;
for (int i = 10; i < N; i++)
dp[i] = add(dp[i - 9], dp[i - 10]);
}
void solve() {
int n, m;
cin >> n >> m;
int len = 0;
while (n) {
int d = n % 10; n /= 10;
if (d + m < 10)
len = add(len, 1);
else
len = add(len, dp[m - (10 - d)]);
}
cout << len << '\n';
}
#define GOOGLE 0
#define MULTIPLE_TC 1
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
pre();
int t = 1, T;
if (MULTIPLE_TC)
cin >> t;
for (T = 1; T <= t; T++) {
if (GOOGLE)
cout << "Case #" << T << ": ";
solve();
}
ktj();
}
| 9 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n); for(auto& a : v) init(a, x, m...); }
const int m = 2e5;
const ll MOD = 1e9+7;
int dp[10][m+1];
int main(int argc, char** argv) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
int T = 1;
cin >> T;
FOR(x, 10) dp[x][0] = 1;
FOR1(i, m){
FOR(x, 9){
dp[x][i] = dp[x+1][i-1];
}
dp[9][i] = (dp[1][i-1] + dp[0][i-1]) % MOD;
}
FOR1(t, T){
int n, m;
cin >> n >> m;
ll sol = 0;
while(n){
int d = n%10;
sol += dp[d][m];
n /= 10;
}
sol %= MOD;
cout << sol << endl;
}
if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
return 0;
}
| 9 |
CPP
|
import sys
input = sys.stdin.readline
mod = 10**9+7
maxx = (2*10**5)+20
from collections import Counter
ans = [1]*maxx
for i in range(10, maxx):
ans[i] = (ans[i-9]+ans[i-10])%mod
for nt in range(int(input())):
n, m = map(int,input().split())
fans = 0
n = str(n)
for digit in n:
# d = {}
# for i in range(10):
# d[i] = 0
# d[int(digit)] = 1
# for j in range(m):
# new_d = {}
# new_d[1] = (d[0]+d[9])%mod
# new_d[0] = d[9]%mod
# for i in range(2, 10):
# new_d[i] = d[i-1]%mod
# d = new_d
# s = 0
# for i in d:
# s += d[i]
fans += ans[m+int(digit)]
fans %= mod
# print (len(ans))
# print (Counter(ans))
print (fans%mod)
| 9 |
PYTHON3
|
import sys
input = sys.stdin.readline
mod=10**9+7
mxi=210000
ans=[0]*mxi
cts=[0]*10
cts[0]=1
s=1
for i in range(mxi):
ans[i]=s
s+=cts[-1]
s%=mod
cts[0]+=cts[-1]
cts[0]%=mod
cts.insert(0,cts.pop())
for f in range(int(input())):
n,m=map(int,input().split())
sol=0
for x in str(n):
sol+=ans[m+int(x)]
sol%=mod
print(sol)
| 9 |
PYTHON3
|
from sys import stdin,stdout
z=10**9+7
dp={}
for i in range(200009):
if i<9:
dp[i]=2
elif i==9:
dp[i]=3
else:
dp[i]=(dp[i-9]+dp[i-10])%z
for _ in range(int(input())):
n,m=stdin.readline().split()
n=int(n);m=int(m)
ans=0
while n>0:
i=n%10
if (m+i)<10:
ans+=1
else:
ans+=((dp[m+i-10])%z)
ans=ans%z
n//=10
stdout.write(str(ans)+'\n')
| 9 |
PYTHON3
|
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
import math
from collections import Counter
# import sys
# sys.setrecursionlimit(10 ** 9)
CACHES = []
for i in range(10):
CACHES.append(1)
for i in range(10, 2 * 10 ** 5 + 10):
CACHES.append((CACHES[i - 9] + CACHES[i - 10]) % (10 ** 9 + 7))
def step(count):
if CACHES[count] is not None:
return CACHES[count]
if count < 10:
CACHES[count] = 1
return CACHES[count]
val = step(count - 9) + step(count - 10)
# CACHES[count] = val % (10 ** 9 + 7)
return val % (10 ** 9 + 7)
def func(array):
n, m = array
count = 0
digits = [int(i) for i in str(n)]
for digit in digits:
count += step(digit + m) % (10 ** 9 + 7)
return count % (10 ** 9 + 7)
def main():
num_test = int(parse_input())
result = []
for _ in range(num_test):
array = [int(i) for i in parse_input().split()]
result.append(func(array))
# print(CACHES[3][:10])
print("\n".join(map(str, result)))
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
parse_input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
| 9 |
PYTHON3
|
from sys import stdin, stdout, maxsize
R = lambda : stdin.readline().strip()
RL = lambda f=None: list(map(f, R().split(' '))) if f else list(R().split(' '))
output = lambda x: stdout.write(str(x) + '\n')
output_list = lambda x: output(' '.join(map(str, x)))
M = int(1e9) + 7
mx = int(2e5) + 5
dp = [0]+9*[1] +[2] + mx*[0]
for i in range(11, len(dp)):
dp[i] = (dp[i-9] + dp[i-10])%M
for tc in range(int(R())):
n, m = RL(int)
ans = 0
for i in list(str(n)):
ans = (ans +dp[int(i) + m])%M
print(ans)
| 9 |
PYTHON3
|
import sys, math
import heapq
from collections import deque
input = sys.stdin.readline
#input
def ip(): return int(input())
def sp(): return str(input().rstrip())
def mip(): return map(int, input().split())
def mfp(): return map(float, input().split())
def msp(): return map(str, input().split())
def lmip(): return list(map(int, input().split()))
def lmsp(): return list(map(str, input().split()))
#gcd, lcm
def gcd(x, y):
while y:
x, y = y, x % y
return x
def lcm(x, y):
return x * y // gcd(x, y)
#prime
def isPrime(x):
if x==1: return False
for i in range(2, int(x**0.5)+1):
if x%i==0:
return False
return True
# Union Find
# p = {i:i for i in range(1, n+1)}
def find(x):
if x == p[x]:
return x
q = find(p[x])
p[x] = q
return q
def union(x, y):
global n
x = find(x)
y = find(y)
if x != y:
p[y] = x
def getPow(a, x):
ret =1
while x:
if x&1:
ret = (ret*a) % MOD
a = (a*a)%MOD
x>>=1
return ret
def getInv(x):
return getPow(x, MOD-2)
############### Main! ###############
MOD = 10**9 + 7
dp = [0 for _ in range(202020)]
for i in range(9):
dp[i]=2
dp[9]=3
for i in range(10,202020):
dp[i] = (dp[i-9]+dp[i-10])%MOD
t = ip()
while t:
ans=0
t -= 1
n,k = mip()
while n:
if k+n%10<10:
ans += 1
else:
ans += dp[k + n%10 - 10]
n//=10
print(ans%MOD)
######## Priest W_NotFoundGD ########
| 9 |
PYTHON3
|
from sys import stdin,stdout
dp=[]
M=10**9+7
for i in range(200011):
if i<10:
dp.append(1)
else:
dp.append((dp[i-9]+dp[i-10])%M)
for _ in range(int(stdin.readline())):
n,m=stdin.readline().split()
m=int(m)
M=10**9+7
ans=0
for i in n:
ans=(ans+dp[m+int(i)])%M
stdout.write(str(ans)+'\n')
| 9 |
PYTHON3
|
//Template Starts Here
//Headers
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <cfloat>
#include <sstream>
#include <unordered_set>
#include <queue>
#include <deque>
#include <iomanip>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cctype>
using namespace std;
//For fast I/O
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
// // Magic
// template <typename... T>
// void read(T &...args)
// {
// ((cin >> args), ...);
// }
// template <typename... T>
// void write(T &...args)
// {
// ((cout << args << " "), ...);
// }
// For printing
#define p0(a) cout << a << " "
#define p1(a) cout << a << "\n"
#define p2(a, b) cout << a << " " << b << "\n"
#define p3(a, b, c) cout << a << " " << b << " " << c << "\n"
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << "\n"
#define p5(a, b, c, d, e) cout << a << " " << b << " " << c << " " << d << " " << e << "\n"
#define fsp(n) fixed << setprecision(n)
#define pfi(x) printf("%d\n", x);
#define pfi2(x, y) printf("%d %d\n", x, y);
#define pfi3(x, y, z) printf("%d %d %d\n", x, y, z);
#define pfl(x) printf("%lld\n", x);
#define pfl2(x, y) printf("%lld %lld\n", x, y);
#define pfl3(x, y, z) printf("%lld %lld %lld\n", x, y, z);
#define pfs(x) printf("%s\n", x);
#define pfs2(x, y) printf("%s %s\n", x, y);
#define pfs3(x, y, z) printf("%s %s %s\n", x, y, z);
#define ia(arr, n) \
f0(i, n) { cin >> arr[i]; }
#define pa(arr, n) \
f0(i, n) { cout << arr[i] << " "; } \
cout << "\n";
//Scanf
#define sf1(a) scanf("%d", &a)
#define sf2(a, b) scanf("%d %d", &a, &b)
#define sf3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define sf4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define sf5(a, b, c, d, e) scanf("%d %d %d %d %d", &a, &b, &c, &d, &e)
#define sf1l(a) scanf("%I64d", &a)
#define sf2l(a, b) scanf("%I64d %I64d", &a, &b)
#define sf3l(a, b, c) scanf("%I64d %I64d %I64d", &a, &b, &c)
#define sf4l(a, b, c, d) scanf("%I64d %I64d %I64d %I64d", &a, &b, &c, &d)
#define sf5l(a, b, c, d, e) scanf("%I64d %I64d %I64d %I64d %I64d", &a, &b, &c, &d, &e)
// Short Forms
#define ld long double
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define al(x, n) (x), (x) + n
#define mp make_pair
#define sz size()
#define clr clear()
#define len length()
// Constant
#define Mod 1000000007
#define Mod2 998244353
#define INF 2147483647
const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230;
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
// Self Defined
#define gcd __gcd
#define lcm(a, b) (a * b) / gcd(a, b)
#define rsort(r) sort(r, greater<ll>())
#define ABS(r) ((r) < 0 ? -(r) : (r))
#define deb(x) cout << ">> " << #x << " : " << x << endl;
// Max - Min
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)
#define max4(a, b, c, d) max(a, max3(b, c, d))
#define min4(a, b, c, d) min(a, min3(b, c, d))
#define max5(a, b, c, d, e) max(max4(a, b, c, d), e)
#define min5(a, b, c, d, e) min(min4(a, b, c, d), e)
#define maxa(v) *max_element(v, v + v.size())
#define mina(v) *min_element(v, v + v.size())
//remain
#define f0(i, n) for (ll i = 0; i < n; i++)
#define f1(i, n) for (ll i = 1; i <= n; i++)
#define f3(i, n) for (ll i = n - 1; i >= 0; i--)
#define f4(i, n) for (ll i = n; i > 0; i--)
// Type Def Start
typedef int64_t ll;
// typedef int64_t ll;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<char, int> mci;
typedef map<int, string> mis;
typedef unordered_map<string, int> usi;
typedef unordered_map<int, int> uii;
typedef unordered_map<ll, ll> ull;
typedef unordered_map<char, int> uci;
typedef unordered_map<int, string> uis;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
typedef pair<int, pii> tri;
typedef pair<double, double> pd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<pii> vpi;
typedef priority_queue<int, vector<int>, greater<int>> rpq;
typedef priority_queue<int> pq;
typedef set<int> si;
typedef set<ll> sl;
// Defined
#define test() \
ll test_case; \
cin >> test_case; \
while (test_case--)
#define inp1(n) \
ll n; \
cin >> n; \
ll arr[n] = {0}; \
f0(i, n) { cin >> arr[i]; }
#define inp2(n, k) \
int n, k; \
cin >> n; \
cin >> k; \
int arr[n] = {0}; \
f0(i, n) { cin >> arr[i]; }
//MODED DATA
// ll add(ll a, ll b)
// {
// ll t = a + b;
// if (t >= mod)
// {
// return t -= mod;
// }
// return t;
// }
// ll sub(ll a, ll b)
// {
// return (a - b + mod) % mod;
// }
// ll mul(ll a, ll b)
// {
// return (a * b) % mod;
// }
//DECIMAL DATA
// const long double eps = 1e-9;
// bool equalTo(double a, double b)
// {
// if (fabs(a - b) <= eps)
// return true;
// else
// return false;
// }
// bool notEqual(double a, double b)
// {
// if (fabs(a - b) > eps)
// return true;
// else
// return false;
// }
// bool lessThan(double a, double b)
// {
// if (a + eps < b)
// return true;
// else
// return false;
// }
// bool lessThanEqual(double a, double b)
// {
// if (a < b + eps)
// return true;
// else
// return false;
// }
// bool greaterThan(double a, double b)
// {
// if (a > b + eps)
// return true;
// else
// return false;
// }
// bool greaterThanEqual(double a, double b)
// {
// if (a + eps > b)
// return true;
// else
// return false;
// }
//Funtions
template <typename T>
int to_int(T num)
{
int val;
stringstream stream;
stream << num;
stream >> val;
return val;
}
bool isPrime(ll n)
{
if (n < 2)
return false;
for (ll i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
bool isPowerTwo(ll x)
{
return (x && !(x & (x - 1)));
};
bool isSubstring(string s1, string s2)
{
if (s1.find(s2) != string::npos)
return true;
return false;
}
ll mod = 1;
ll fast_pow(ll a, ll p)
{
ll res = 1;
while (p)
{
if (p % 2 == 0)
{
a = a * 1ll * a;
p /= 2;
}
else
{
res = res * 1ll * a;
p--;
}
}
return res;
}
ll fact(ll n)
{
ll res = 1;
for (ll i = 1; i <= n; i++)
{
res = res * 1ll * i % mod;
}
return res;
}
ll nCr(ll n, ll k)
{
return fact(n) * 1ll * fast_pow(fact(k), mod - 2) % mod * 1ll * fast_pow(fact(n - k), mod - 2) % mod;
}
ll gcd(ll a, ll b)
{
if (b > a)
{
return gcd(b, a);
}
if (b == 0)
{
return a;
}
return gcd(b, a % b);
}
ll expo(ll a, ll b, ll mod)
{
ll res = 1;
while (b > 0)
{
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b = b >> 1;
}
return res;
}
void extendgcd(ll a, ll b, ll *v)
{
if (b == 0)
{
v[0] = 1;
v[1] = 0;
v[2] = a;
return;
}
extendgcd(b, a % b, v);
ll x = v[1];
v[1] = v[0] - v[1] * (a / b);
v[0] = x;
return;
} //pass an arry of size1 3
ll mminv(ll a, ll b)
{
ll arr[3];
extendgcd(a, b, arr);
return arr[0];
} //for non prime b
ll mminvprime(ll a, ll b) { return expo(a, b - 2, b); }
bool revsort(ll a, ll b) { return a > b; }
void swap(int &x, int &y)
{
int temp = x;
x = y;
y = temp;
}
ll combination(ll n, ll r, ll m, ll *fact, ll *ifact)
{
ll val1 = fact[n];
ll val2 = ifact[n - r];
ll val3 = ifact[r];
return (((val1 * val2) % m) * val3) % m;
}
void google(int t) { cout << "Case #" << t << ": "; }
vector<ll> sieve(int n)
{
int *arr = new int[n + 1]();
vector<ll> vect;
for (int i = 2; i <= n; i++)
if (arr[i] == 0)
{
vect.push_back(i);
for (int j = 2 * i; j <= n; j += i)
arr[j] = 1;
}
return vect;
}
ll mod_add(ll a, ll b, ll m)
{
a = a % m;
b = b % m;
return (((a + b) % m) + m) % m;
}
ll mod_mul(ll a, ll b, ll m)
{
a = a % m;
b = b % m;
return (((a * b) % m) + m) % m;
}
ll mod_sub(ll a, ll b, ll m)
{
a = a % m;
b = b % m;
return (((a - b) % m) + m) % m;
}
ll mod_div(ll a, ll b, ll m)
{
a = a % m;
b = b % m;
return (mod_mul(a, mminvprime(b, m), m) + m) % m;
} //only for prime m
//Template Completed
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// sort(s.begin(), s.end());
//distance(s.begin(), unique(s.begin(), s.end()))
//s.resize(distance(s.begin(), unique(s.begin(), s.end())))
void check(bool b, string y = "YES", string n = "NO")
{
// b ? cout << "YES\n" : cout << "NO\n";
b ? cout << y << "\n" : cout << n << "\n";
}
bool cmp(pair<ll, ll> a, pair<ll, ll> b)
{
if (a.first < b.first)
return false;
if (a.first > b.first)
return true;
else
return a.second < b.second;
}
void sol6()
{
ll n;
cin >> n;
string s[n];
for (ll x = 0; x < n; x++)
{
cin >> s[x];
}
}
void sol5()
{
ll a, b;
cin >> a >> b;
ll a2 = a, b2 = b;
string s;
cin >> s;
}
void sol4()
{
ll n;
cin >> n;
ll a[n];
for (ll i = 0; i < n; i++)
{
cin >> a[i];
}
}
void sol3()
{
ll n, k;
cin >> n >> k;
}
const ll N = 2 * 1e5 + 10;
ll dp[10][N];
void solve()
{
//Initial Single Digit for Each
for (ll i = 0; i <= 9; i++)
{
dp[i][0] = 1;
}
for (ll j = 1; j < N; j++)
{
//All digits increase only but digits are same
for (ll i = 0; i <= 8; i++)
{
dp[i][j] = dp[i + 1][j - 1];
}
//9 break in 0 and 1
dp[9][j] = mod_add(dp[0][j - 1], dp[1][j - 1], Mod);
}
}
void sol2()
{
ll n, m;
cin >> n >> m;
vector<ll> v(10, 0);
while (n != 0)
{
ll rem = n % 10;
v[rem]++;
n /= 10;
}
ll ans = 0;
for (ll i = 0; i < 10; i++)
{
ll x = dp[i][m];
ll y = v[i];
ans = mod_add(mod_mul(x, y, Mod), ans, Mod);
}
p1(ans);
}
void sol()
{
ll n, l, r, s;
cin >> n >> l >> r >> s;
}
int main()
{
fast;
solve();
test()
{
sol2();
}
}
| 9 |
CPP
|
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mk make_pair
#define pb push_back
const int inf=0x3f3f3f3f;
const int maxn=2e5+10;
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
void useiostream()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
ll num[15]={0};
ll nex[15]={0};
ll dp[15][maxn]={0};
void init1()
{
ll ans=0;
for(int i=0;i<=9;i++)
{
dp[i][0]=1;
}
for(int k=0;k<=9;k++)
{
for(int h=0;h<=9;h++)
{
if(h==k)num[h]=1;
else num[h]=0;
}
ans=1;
for(int j=1;j<maxn;j++)
{
for(int i=0;i<=9;i++)
{
if(i==1)
{
nex[i]=(num[0]+num[9])%mod;
}
else if(i==0)nex[0]=num[9];
else nex[i]=num[i-1];
}
ans=(ans+num[9])%mod;
for(int i=0;i<=9;i++)
{
num[i]=nex[i];
}
dp[k][j]=ans;
}
}
}
int main()
{
useiostream();
int T;
cin>>T;
init1();
while(T--)
{
string str;
cin>>str;
ll ans1=0;
int m;
cin>>m;
for(int i=0;i<str.size();i++)
{
ans1=(ans1+dp[str[i]-'0'][m])%mod;
}
cout<<ans1<<endl;
}
}
| 9 |
CPP
|
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define fr(i,n) for(int i=0;i<n;i++)
#define fr1(i,k,n) for(int i=k;i<n;i++)
#define foreach(i,arr) for(auto i: arr)
#define sort_inc(a) sort(a.begin(),a.end())
#define sort_dec(a) sort(a.begin(),a.end(),greater<>())
#define exists(a,val) find(a.begin(),a.end(),val)!=a.end()
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T mod(T a){ a %= MOD; if (a<0) a += MOD; return a; }
template <typename T> T add(T a, T b){ return mod(a+b); }
template <typename T> T mul(T a, T b){ return (a * 1ll * b) % MOD; }
template <typename T> T binPow(T a, T b){ T res = 1; while (b>0){ if (b&1) res = mul<T>(res, a); a = mul<T>(a,a); b >>= 1; } return res; }
const int N = 2*1e5 + 5;
int dp[10][N];
void solve(){
int n,m;
cin>>n>>m;
vector<int> a(10);
int n1=n;
while(n1){
a[n1%10]++;
n1 /= 10;
}
int res = 0;
for (int i=0;i<10;i++){
res = add(res, mul(dp[i][m], a[i]));
}
cout<<res<<"\n";
}
int main(int argc, const char * argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
for (int i=0;i<10;i++) dp[i][0] = 1;
for (int i=1;i<N;i++){
for (int j=0;j<=8;j++){
dp[j][i] = dp[j+1][i-1];
}
dp[9][i] = add(dp[0][i-1],dp[1][i-1]);
}
int t=1;
cin>>t;
for (int i=0;i<t;i++){
solve();
}
return 0;
}
| 9 |
CPP
|
#include <cmath>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <fstream>
#include <cassert>
using namespace std;
istream& inp = cin;
//ifstream inp("in");
template<typename T>
vector<T> readV(int size) {
vector<T> result;
for (int i = 0; i < size; ++i) { T x; inp >> x; result.push_back(x); }
return result;
}
template<typename T>
T divup(T a, T b) { if ((a % b) == 0) return a / b; return 1 + a / b; }
int64_t constexpr M = 1000000007;
static_assert( M <= (1 << 30));
class modint {
int v;
public:
modint(int x) : v(x % M) {}
modint() : v(0) {}
inline int get() const { return v; }
modint operator + (modint b) { return modint(v + b.v); }
};
vector<modint> len9(200010);
string ns[200010];
int ms[200010];
int32_t main() {
int ntests;
assert(inp);
inp >> ntests;
len9[0] = modint(1);
for (int i = 1; i <= 9; ++i) len9[i] = modint(2);
len9[10] = modint(3);
for (int i = 11; i < 200010; ++i) len9[i] = (len9.at(i - 9) + len9.at(i - 10));
for (int test = 0; test < ntests; ++test ) {
string n;
int n0, m;
inp >> ns[test] >> ms[test];
}
for (int test = 0; test < ntests; ++test ) {
string& n = ns[test];
int m = ms[test];
int64_t result = 0;
assert(n.size() <= 11);
for (int i = 0; i < n.size(); ++i) {
char c = n[i];
assert(c >= '0' && c <= '9');
int m1 = m - (int('9') - int(c));
if (m1 <= 0) result = result + (1); else {
result = result + len9[m1].get();
}
}
cout << (result % M) << "\n";
}
return 0;
}
| 9 |
CPP
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 233333;
const ll mod = 1e9 + 7;
ll dp[10][N];
int main() {
int m = 200011;
for(int i = 0; i <= 9; ++i) dp[i][0] = 1;
for(int i = 1; i <= m; ++i) {
for(int d = 0; d <= 9; ++d) {
if(d <= 8) {
dp[d][i] = dp[d+1][i-1];
} else {
dp[d][i] = (dp[1][i-1] + dp[0][i-1]) % mod;
}
}
}
int T, n, k;
cin >> T;
while(T--) {
scanf("%d %d", &n, &k);
int x = n;
ll ans = 0;
while(x) {
int bit = x % 10;
x /= 10;
ans = (ans + dp[bit][k]) % mod;
}
printf("%lld\n", (ans+mod) % mod);
}
}
| 9 |
CPP
|
import sys
input = sys.stdin.readline
MOD = 1000000007
dp = [1 for _ in range(200010)]
for i in range(10, 200010):
dp[i] = (dp[i-10]+dp[i-9]) % MOD
for _ in range(int(input())):
n, m = map(int, input().split())
ans = 0
while n:
ans += dp[m+n % 10]
n //= 10
ans %= MOD
print(ans)
| 9 |
PYTHON3
|
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdlib>
#include <iomanip>
#include<climits>
#include<fstream>
using namespace std;
//=========================MACROS====================================
#define GSK ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ll long long
#define fo(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define PI 3.1415926535897932384626
#define mod 1000000007;
#define print2(a,b) cout<<#a<<"="<<(a)<<" "<<#b<<"="<<(b)<<endl;
#define print3(a,b,c) cout<<#a<<"="<<(a)<<" "<<#b<<"="<<(b)<<" "<<#c<<"="<<(c)<<endl;
#define endl "\n"
#define runtime() ((double)clock() / CLOCKS_PER_SEC)
//========================TypeDefs===================================
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef vector<ii> vii;
//======================== JFF ==================================
//void* memset( void* str, int ch, size_t n);
// bool isprime(int n){
// for(int i=2;i<=sqrt(n);i++){
// if(n%i==0) return false;
// }
// return true;
// }
// const int N=1e6+1;
// bool prime[N];
// void SieveOfEratosthenes(int n)
// {
// // Create a boolean array
// // "prime[0..n]" and initialize
// // all entries it as true.
// // A value in prime[i] will
// // finally be false if i is
// // Not a prime, else true.
// memset(prime, true, sizeof(prime));
// for (int p = 2; p * p <= n; p++)
// {
// // If prime[p] is not changed,
// // then it is a prime
// if (prime[p] == true)
// {
// // Update all multiples
// // of p greater than or
// // equal to the square of it
// // numbers which are multiple
// // of p and are less than p^2
// // are already been marked.
// for (int i = p * p; i <= n; i += p)
// prime[i] = false;
// }
// }
// // Print all prime numbers
// // for (int p = 2; p <= n; p++)
// // if (prime[p])
// // cout << p << " ";
// }
// inline ll power(ll x, ll y, ll p = mod)
// {
// ll res = 1;
// x = x % p;
// while (y > 0)
// {
// if (y & 1)
// res = (res * x) % p;
// y = y >> 1;
// x = (x * x) % p;
// }
// return res;
// }
// inline ll modadd(ll a, ll b, ll m = mod)
// {
// a += b;
// if (a >= m)
// a -= m;
// return a;
// }
// inline ll modmul(ll a, ll b, ll m = mod)
// {
// return ((a % m) * (b % m)) % m;
// }
// inline ll modi(ll a, ll m = mod) { return power(a, m - 2, m); }
// long long int inverse(long long int i,ll m=mod){
// if(i==1) return 1;
// return (m - ((m/i)*inverse(m%i))%m+m)%m;
// }
void hehe(bool ok){
cout<<(ok?"YES":"NO")<<endl;
}
int foo(int a,int b){
return b*((a+b-1)/b)-a;
}
//======================== JFF ==================================
const int M=200015;
int pre[M];
void q1(){
int n,m;
cin>>n>>m;
vi a;
while(n>0){
a.pb(n%10);
n/=10;
}
int ans=0;
for(int x: a){
ans=(ans+pre[x+m])%mod;
}
cout<<ans<<endl;
}
/*
1
2 1 1 3
*/
int32_t main()
{
GSK;
// fo(i,N) fac[i]=1;
// for(int i=1;i<N;i++){
// fac[i]=(fac[i-1]*i)%mod;
// }
fo(i,10) pre[i]=1;
for(int i=10;i<M;i++){
pre[i]=(pre[i-10]+pre[i-9])%mod;
}
int cases=1;
cin >> cases;
for(int t_case=1;t_case<=cases;t_case++)
{
// cout<<"Case #"<<t_case<<": ";
q1();
}
//cerr<<runtime();
return 0;
}
| 9 |
CPP
|
import sys
input = sys.stdin.readline
dp = []
M = 10 ** 9 + 7
for i in range(200011):
if i < 10:
dp.append(1)
else:
dp.append((dp[i - 9] + dp[i - 10]) % M)
for _ in range(int(input())):
n, m = input().split()
m = int(m)
M = 10 ** 9 + 7
ans = 0
for i in n:
ans = (ans + dp[m + int(i)]) % M
print(ans)
| 9 |
PYTHON3
|
#include <bits/stdc++.h>
#define PI 3.14159265359
#define lp(i, n) for (size_t i = 0; i < n; i++)
typedef long long ll;
typedef long double ld;
using namespace std;
const char nl = '\n';
const ll MOD = (ll)1e9 + 7;
vector<ll> lenDigit(int d, int m) {
ll occ[10] = {0};
occ[d] = 1;
vector<ll> v;
v.push_back(1);
while (m--) {
ll nine = occ[9];
for (int i = 9; i > 0; i--) {
occ[i] = occ[i - 1];
}
occ[0] = nine;
occ[1] += nine;
occ[1] %= MOD;
v.push_back((v.back() + nine) % MOD);
}
return v;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
vector<ll> res[10];
for (int i = 0; i < 10; i++) {
res[i] = lenDigit(i, 2 * (int)1e5);
}
while (t--) {
ll n;
int m;
cin >> n >> m;
ll ret = 0;
while (n) {
ret += res[n % 10][m];
ret %= MOD;
n /= 10;
}
cout << ret << nl;
}
return 0;
}
| 9 |
CPP
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,n) for(ll i=a ;i<n ;i++)
#define fr(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define read(a,n) for(ll i=0 ;i<n ;i++)cin>>a[i]
#define F first
#define S second
#define endl "\n"
bool pali(string s)
{
for(ll i=0 ;i<s.size()/2 ;i++)
if(s[i]!=s[s.size()-i-1])
return false;
return true;
}
void no(){
cout<<-1<<endl;
}
void yes(){
cout<<"YES\n";
}
ll mod=1000000007;
///////////////////////////////////////////////////////////////////
ll dp[10][200005]={0};
ll solve(int n ,int m)
{
if(m<10-n)
return 1;
if(dp[n][m]!=0)
return dp[n][m]%mod;
else{
dp[n][m]=((solve(1,m-(10-n))%mod)+(solve(0,m-(10-n)))%mod)%mod;
return dp[n][m];
}
}
int size(int n)
{
int ans=0;
while(n>0)
{
ans++;
n/=10;
}
return ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll t = 1;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
ll ans=0;
while(n>0)
{
ans+=(solve(n%10,m)%mod);
ans%=mod;
n/=10;
}
cout<<ans<<endl;
}
return 0;
}
| 9 |
CPP
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int max_n = 200005, mod = 1000000007;
int p[max_n];
signed main() {
for (int i = 0; i < 9; i ++)p[i] = 2;
p[9] = 3;
for (int i = 10; i < max_n; i ++) {
p[i] = (p[i - 9] + p[i - 10]) % mod;
}
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t --) {
int n, m;
cin >> n >> m;
int ans = 0;
while (n > 0) {
int x = n % 10;
ans += ((m + x < 10) ? 1 : p[m + x - 10]);
ans %= mod;
n /= 10;
}
cout << ans << "\n";
}
return 0;
}
| 9 |
CPP
|
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
long long t,n,sum[10],total[200001],temp,temp1,temp2,inf=1000000007,j,ans,formulation;
long long i,m,xiao=200000;
for(i=0; i<10; i++)
sum[i]=0;
sum[0]=1;
sum[1]=1;
total[0]=2;
for(i=1; i<=xiao; i++)
{
temp=sum[8]%inf;
sum[8]=sum[7]%inf;
sum[7]=sum[6]%inf;
sum[6]=sum[5]%inf;
sum[5]=sum[4]%inf;
sum[4]=sum[3]%inf;
sum[3]=sum[2]%inf;
sum[2]=sum[1]%inf;
sum[1]=sum[0]%inf+sum[9]%inf;
sum[0]=sum[9]%inf;
sum[9]=temp;
total[i]=(sum[0]+sum[1]+sum[2]+sum[3]+sum[4]+sum[5]+sum[6]+sum[7]+sum[8]+sum[9])%inf;
}
scanf("%lld",&t);
for(j=0; j<t; j++)
{
ans=0;
scanf("%lld%lld",&n,&m);
while(n!=0)
{
formulation=m+n%10-10;
if(formulation<0)
ans=(ans+1)%inf;
else
{
ans=(ans+total[formulation])%inf;
}
n=n/10;
}
printf("%d\n",ans%inf);
}
return 0;
}
| 9 |
CPP
|
import sys
def get_ints(): return map(int, sys.stdin.readline().strip().split())
MOD = 10 ** 9 + 7
LIMIT = 20011
dp = []
for i in range(200011):
if i < 10:
dp.append(1)
else:
dp.append((dp[i - 9] + dp[i - 10]) % MOD)
T = int(input())
for _ in range(T):
N, M = get_ints()
ans = 0
while N:
ans = (ans + dp[N % 10 + M]) % MOD
N //= 10
print(ans)
| 9 |
PYTHON3
|
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <limits>
#include <numeric>
using namespace std;
const int MOD = 1e9 + 7;
struct matrix {
int size = 10;
int a[10][10];
matrix() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
a[i][j] = 0;
}
}
}
matrix operator *(matrix& other) {
matrix product;
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
for (int k = 0; k < size; k++) {
product.a[i][k] += a[i][j] * other.a[j][k] % MOD;
product.a[i][k] %= MOD;
}
}
}
return product;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
vector<matrix> m(200001);
matrix trans;
trans.a[0][9] = 1;
trans.a[1][9] = 1;
for (int i = 1; i <= 9; i++) {
trans.a[i][i - 1] = 1;
}
for (int i = 0; i <= 9; i++) {
m[0].a[i][i] = 1;
}
for (int i = 1; i <= 200000; i++) {
m[i] = trans * m[i - 1];
}
int tt;
cin >> tt;
while (tt--) {
string s;
int k;
cin >> s >> k;
int cnt[10];
for (int i = 0; i < 10; i++) {
cnt[i] = 0;
}
for (char c : s) {
cnt[c - '0']++;
}
long long answer = 0;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
answer = (answer + (long long)m[k].a[i][j] * cnt[j]) % MOD;
}
}
cout << answer << '\n';
}
}
| 9 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int m=200000;
int p=1000000007;
vector<int> dp(m+1);
for(int i=0;i<9;i++){dp[i]=2;}
dp[9]=3;
for(int i=10;i<=m;i++){dp[i]=(dp[i-10]+dp[i-9])%p;}
int t;
cin>>t;
while(t--){
int n,x;
cin>>n>>x;
int ans=0;
while(n!=0){
int d=n%10;
n/=10;
if(d+x<10){ans=(ans+1)%p;}
else{ans=(ans+dp[d+x-10])%p;}
}
cout<<ans<<endl;
}
return 0;
}
| 9 |
CPP
|
M=10**9+7;L=8**6;d=[1]*L;d[:10]=[1]*10
for i in range(10,L):d[i]=(d[i-9]+d[i-10])%M
for s in[*open(0)][1:]:n,m=s.split();o=int(m);print(sum(d[o+int(c)]for c in n)%M)
| 9 |
PYTHON3
|
import sys
input = sys.stdin.readline
dp = [2] * 9 + [3] + [0] * 199991
for i in range(10, 200001): # len after applying i times to 10
dp[i] = (dp[i - 9] + dp[i - 10]) % (10 ** 9 + 7)
for _ in range(int(input())):
n, m = map(int, input().split())
ans = 0
while n:
x = n % 10 # last digit
if m + x < 10:
ans += 1
else:
ans += dp[m + x - 10]
n //= 10
print(ans % (10 ** 9 + 7))
| 9 |
PYTHON3
|
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<functional>
#include<iterator>
int main()
{
vector<int> operate;
for (int i = 0; i < 200001; i++)
{
if (i < 9)
operate.push_back(2);
if (i == 9)
operate.push_back(3);
if (i > 9)
operate.push_back((operate[i - 9] + operate[i - 10]) % 1000000007);
}
int t;
cin >> t;
vector<int> answer;
for (int i = 0; i < t; i++)
{
int n, m;
cin >> n >> m;
answer.push_back(0);
while (n)
{
if (m - 10 + n % 10 >= 0)
{
answer[i] += operate[m - 10 + n % 10];
}
else
answer[i] += 1;
answer[i] %= 1000000007;
n /= 10;
}
}
copy(answer.begin(), answer.end(), ostream_iterator<int>(cout, "\n"));
return 0;
}
| 9 |
CPP
|
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int X=0; bool flag=1; char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
if(flag) return X;
return ~(X-1);
}
int T,n,m;
typedef long long ll;
ll mod=1e9+7,ans=0ll;
ll f[200050];
int main(){
cin>>T;
for(int i=0;i<=8;i++){
f[i]=2ll;
}
for(int i=9;i<=200005;i++){
if(i<10)f[i]=f[i-9]+1;
else f[i]=f[i-9]+f[i-10];
if(f[i]>mod)f[i]%=mod;
}
while(T--){
n=read();m=read();
ans=0ll;
while(n){
int t=n%10;
if(m>=10-t)ans+=f[m-(10-t)];
else ans++;
n/=10;
if(ans>mod)ans%=mod;
}
printf("%d\n",ans%mod);
}
}
| 9 |
CPP
|
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm> // for copy
#include <iterator> // for ostream_iterator
using namespace std;
const int P = 1000000007;
const int M = 200000;
int answer_for_0[M+10];
// the result for the digit 0 is answer_for_0[m]
// the result for any other digit d is answer_for_0[m+d]
int main (){
for (int i=0;i<10;i++)
answer_for_0[i] = 1;
for (int i=10; i<M+10; i++)
answer_for_0[i] = (answer_for_0[i-10] + answer_for_0[i-9])%P;
int t;
cin >> t;
vector<int> answers (t);
for (int i=0; i<t; i++){
int n, m;
cin >>n >>m;
int ans = 0;
while(n > 0){
ans = (ans+ answer_for_0[m+ n%10] )%P ;
n/=10;
}
answers[i] = ans;
}
copy ( answers.begin(), answers.end(), ostream_iterator<int>(cout, "\n") );
return 0;
}
| 9 |
CPP
|
import sys,functools,collections,bisect,math,heapq
input = sys.stdin.readline
#print = sys.stdout.write
mod = 10**9 + 7
sys.setrecursionlimit(300000)
N = 200001
dp = [0]*N
for i in range(9):
dp[i] = 2
dp[9] = 3
for i in range(10,N):
dp[i] = dp[i-9]+dp[i-10]
dp[i] %= mod
t = int(input())
for _ in range(t):
s,m = input().strip().split()
m = int(m)
s = list(map(int,list(s)))
ans = 0
for i in s:
if m-10+i >= 0:
ans += dp[m-10+i]
else:
ans += 1
ans %= mod
print(ans)
| 9 |
PYTHON3
|
import sys
def get_ints(): return map(int, sys.stdin.readline().strip().split())
MOD = 10 ** 9 + 7
LIMIT = 200011
dp = [0] * LIMIT
for i in range(10):
dp[i] = 1
for i in range(10, LIMIT, 1):
dp[i] = (dp[i - 9] + dp[i - 10]) % MOD
def solve(N, M):
ans = 0
while N:
ans = (ans + dp[N % 10 + M]) % MOD
N //= 10
return ans % MOD
T = int(input())
for _ in range(T):
N, M = get_ints()
print(solve(N, M))
| 9 |
PYTHON3
|
// Просто решаю.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//
//KiruxaLight
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <iomanip>
#include <stack>
#include <deque>
#include <queue>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cassert>
#include <bitset>
using namespace std;
#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const int INF = 1e9 + 123, MAXN = 2e5, MEGAINF = 1e18, C = 50;
const int mod = 1e9 + 7;
int dp[10][MAXN + 1];
void init()
{
for (int i = 0; i < 10; ++i)
dp[i][0] = 1;
for (int i = 1; i <= MAXN; ++i)
{
for (int j = 0; j < 9; ++j)
dp[j][i] = dp[j + 1][i - 1];
dp[9][i] = (dp[1][i - 1] + dp[0][i - 1]) % mod;
}
}
signed main()
{
setlocale(LC_ALL, "rus");
/*freopen(".in", "r", stdin);
freopen(".out", "w", stdout);*/
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
init();
/*for (int i = 0; i <= MAXN; ++i, cout << endl)
for (int j = 0; j < 10; ++j)
cout << dp[j][i] << " ";*/
int t;
cin >> t;
while (t--)
{
int n, m;
cin >> n >> m;
int ans = 0;
while (n)
{
ans = (ans + dp[n % 10][m]) % mod;
n /= 10;
}
cout << ans << "\n";
}
}
// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
// Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
// Советы по началу работы
// 1. В окне обозревателя решений можно добавлять файлы и управлять ими.
// 2. В окне Team Explorer можно подключиться к системе управления версиями.
// 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
// 4. В окне "Список ошибок" можно просматривать ошибки.
// 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
// 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.
| 9 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define gap ' '
#define fastIO {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define Inf 1e18
#define MOD 1000000007
#define N 1000006
#define all(v) v.begin(),v.end()
#define For(i, a, b) for(ll i = a; i < b; ++i)
#define Rof(i, a, b) for(ll i = a; i >= b; --i)
#define endl "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef multimap<ll, ll> mmll;
ll dp[200500];
void start() {
For(i, 0, 10) dp[i] = 1;
For(i, 10, 200500)
dp[i] = (dp[i - 10] + dp[i - 9]) % MOD;
}
void solve()
{
ll t; t = 1; cin>>t; t:
start();
while(t --)
{
ll n, m; cin>>n>>m;
ll ans = 0;
while(n)
{
ll k = n%10;
ans = (ans + dp[k + m])%MOD;
n/=10;
}
cout<< ans <<endl;
}
}
int main()
{
fastIO
solve();
return 0;
}
| 9 |
CPP
|
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mxn=2e5+10,mod=1e9+7;
int dp[12][mxn];
int main()
{
int arr[]={1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2};
for(int i=0;i<=9;i++)
for(int j=0;j<10;j++)
dp[i][j]=arr[i+j];
for(int i=0;i<=9;i++)
for(int j=10;j<mxn;j++)
dp[i][j]=(dp[i][j-10]%mod+dp[i][j-9]%mod)%mod;
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
int res=0;
while(n!=0)
{
int rem=n%10;
res=(res%mod+dp[rem][m]%mod)%mod;
n/=10;
}
printf("%d\n",res);
}
return 0;
}
| 9 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int big = pow(10, 9) + 7, size = 200000;
int tt;
cin >> tt;
vector<ll> dp(size+1);
dp[0] = 1;
for (int i = 0; i < size; i++)
{
if (i + 9 < size)
dp[i + 9] = (dp[i + 9] + dp[i]) % big;
if (i + 10 < size)
dp[i + 10] = (dp[i + 10] + dp[i]) % big;
}
for (int i = 1; i < size; i++)
{
dp[i] = (dp[i] + dp[i - 1]) % big;
}
while (tt--)
{
string s;
ll m, ans = 0;
cin >> s >> m;
ans = s.size();
vector<ll> num(10);
for (int i = 0; i < s.size(); i++)
{
int n = s[i] - '0';
num[n]++;
}
for (int i = 0; i < 10; i++)
{
if (m < (10 - i))
continue;
ans = (ans + num[i] * dp[m - (10 - i)]) % big;
}
cout << ans << "\n";
}
return 0;
}
| 9 |
CPP
|
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<stack>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int mod = 1e9 + 7;
ll t, n, m;
int dp[200500];
int main(){
fast;
for (int i = 0; i < 9;i++){
dp[i] = 2;
}
dp[9] = 3;
for (int i = 10; i < 200005;i++){
dp[i] = (dp[i - 9] + dp[i - 10]) % mod;
}
cin >> t;
while(t--){
cin >> n >> m;
ll ans = 0;
while(n>0){
int x = n % 10;
ans += ((m + x < 10) ? 1 : dp[m + x - 10]);
ans %= mod;
n /= 10;
}
cout << ans << "\n";
}
return 0;
}
| 9 |
CPP
|
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
#sys.setrecursionlimit(300000)
#threading.stack_size(10**8)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------------------------------------------------------------
#mod = 9223372036854775807
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b: max(a,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
class SegmentTree1:
def __init__(self, data, default=10**6, func=lambda a, b: min(a,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
MOD=10**9+7
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod=10**9+7
omod=998244353
#-------------------------------------------------------------------------
prime = [True for i in range(10)]
pp=[0]*10
def SieveOfEratosthenes(n=10):
p = 2
c=0
while (p * p <= n):
if (prime[p] == True):
c+=1
for i in range(p, n+1, p):
pp[i]+=1
prime[i] = False
p += 1
#---------------------------------Binary Search------------------------------------------
def binarySearch(arr, n, key):
left = 0
right = n-1
mid = 0
res=0
while (left <= right):
mid = (right + left)//2
if (arr[mid][0] > key):
right = mid-1
else:
res=mid
left = mid + 1
return res
#---------------------------------running code------------------------------------------
dp=[]
M=10**9+7
for i in range(200011):
if i<10:
dp.append(1)
else:
dp.append((dp[i-9]+dp[i-10])%M)
for _ in range(int(input())):
n,m=map(int,input().split())
M=10**9+7
ans=0
for i in str(n):
ans=(ans+dp[m+int(i)])%M
print(ans)
| 9 |
PYTHON3
|
#include<bits/stdc++.h>
#define MAX 200000
#define MOD 1000000007
using namespace std;
int dp[11][MAX+10];
int go(int x,int m)
{
if(dp[x][m]!=-1)
return dp[x][m];
if(m==0)
return dp[x][m] = 1;
if(x==9)
return dp[x][m] = (go(1,m-1)+go(0,m-1))%MOD;
return dp[x][m] = go(x+1,m-1);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
for(int i=0;i<=9;++i)
for(int j=0;j<=MAX;++j)
dp[i][j] = -1;
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
int m;
cin>>m;
long long ans = 0;
for(char c:s)
ans += go(c-'0',m)*1LL, ans %= MOD;
cout<<ans<<endl;
}
return 0;
}
| 9 |
CPP
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <bitset>
#include <math.h>
#include <fstream>
#include <iomanip>
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vld = vector<ld>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using pb = pair<bool, bool>;
using vpb = vector<pb>;
using vvpb = vector<vpb>;
using vi = vector<int>;
const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e18;
#define F first
#define S second
#define FAST ios_base::sync_with_stdio(0)
#define FASTIN cin.tie(0)
#define FASTOUT cout.tie(0)
#define upmin(a, b) a = min(a, b)
#define upmax(a, b) a = max(a, b)
#define whatvec(v) cout << #v << ": "; for(auto it = v.begin(); it != v.end(); ++it) cout << *it << " "; cout << endl;
#define prv(v) cout << #v << ": "; for(auto it = v.begin(); it != v.end(); ++it) cout << *it << " "; cout << endl;
#define wpr(x) cout << #x << " = " << (x) << endl;
#define wprv(v) cout << #v << ": "; for(auto it = v.begin(); it != v.end(); ++it) cout << *it << " "; cout << endl;
#define what(x) cout << #x << " = " << (x) << "\n";
#define pr(x) cout <<x << endl;
#define rep(i,s,e) for(int i=s;i<e;i++)
#define all(x) x.begin(),x.end()
#define pb push_back
// 13:52
const ll maxn = 2e5 + 5;
vvll dp; // [len][dig]
void init_dp()
{
dp.resize(maxn, vll(10, 1));
for (ll i = 1; i < maxn; i++) {
for (ll dig = 0; dig < 9; dig++) {
dp[i][dig] = (dp[i - 1][dig + 1])%mod;
}
dp[i][9] = (dp[i - 1][1] + dp[i - 1][0])%mod;
}
}
void solve()
{
ll n, m;
cin >> n >> m;
ll ans = 0;
while (n) {
ll d = n % 10;
ans += dp[m][d];
ans %= mod;
n /= 10;
}
pr(ans);
}
int main()
{
init_dp();
FAST;
ll test;
cin >> test;
while (test--)
{
solve();
}
}
| 9 |
CPP
|
#include<bits/stdc++.h>
using namespace std;
long long m=200000,k=1;
long long sum[200001][10]={{}};
long long a[10]={1,1,1,1,1,1,1,1,1,1},b[10];
int main(){
ios_base::sync_with_stdio(false);
long long j=9;
k=1;
ios_base::sync_with_stdio(false);
for(long long i=0;i<=9;i++)
a[i]=0;
a[j]=1;
while(k<=m)
{
for(long long i=0;i<=9;i++)
b[i]=0;
for(long long i=0;i<=9;i++){
if(i<=8)
{
b[i+1]+=a[i];
b[i+1]%=1000000007;}
else if(i==9)
{
b[1]+=a[i];b[0]+=a[i];
b[1]%=1000000007;b[1]%=1000000007;}
a[i]=0;
}
ios_base::sync_with_stdio(false);
//if(k==1&&j==9)
//cout<<b[9]<<endl;
for(long long i=0;i<=9;i++)
a[i]=b[i];
for(long long i=0;i<=9;i++)
{
sum[k][j]+=a[i];
sum[k][j]%=1000000007;
}
k++;}
ios_base::sync_with_stdio(false);
long long t;
cin>>t;
while(t--){
ios_base::sync_with_stdio(false);
long long n,m;
cin>>n>>m;
long long p=0;
while(n!=0){
long long x;
x=n%10;
if(x==9)
p+=sum[m][x];
else if(m>(9-x))
p+=sum[m-9+x][9];
else
p+=1;
p%=1000000007;
n=n/10;
}
cout<<p<<endl;
}
//cout<<"5\n2\n6\n4\n2115";
}
| 9 |
CPP
|
#include<bits/stdc++.h>
#define mp make_pair
#define s second
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(),v.end()
#define mx(a,b) a>b?a:b
#define mn(a,b) a<b?a:b
using namespace std;
const int maxn = 5+2e5;
typedef long long ll;
const int mod = 1e9+7;
int dp[maxn];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for(int i = 0;i < 9;i++)dp[i] = 2;
dp[9] = 3;
for(int i = 10;i < maxn;i++){
dp[i] = (dp[i-9] + dp[i-10]) % mod;
}
while(t--){
ll sol = 0;
string k;
int m;
cin >> k >> m;
for(auto i: k){
if(m + (int)(i-'0') < 10)sol++;
else sol += dp[m-10+(int)(i-'0')];
sol %= mod;
}
cout << sol << "\n";
}
}
| 9 |
CPP
|
from sys import stdin
input = stdin.readline
mod = 10**9 + 7
cnt = [1]*(2*10**5+15)
curr = [1,0,0,0,0,0,0,0,0,0]
curr_len = 1
for i in range(2*10**5 + 15):
cnt[i]=curr_len
curr_len = (curr_len + curr[-1])%mod
curr[0] = (curr[0]+curr[-1])%mod
curr.insert(0,curr.pop())
for _ in range(int(input())):
n,m = map(int,input().split())
ans=0
for i in str(n):
ans=(ans+cnt[int(i)+m])%mod
print(ans)
| 9 |
PYTHON3
|
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i = k ;i<=n;i++)
#define FO(i,n,k) for(int i = n;i>=k;i--)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define mems(a,x) memset(a,x,sizeof(a))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<pair<int, int> , int > piii;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
uniform_int_distribution<int> uid(0, lim - 1);
return uid(rang);
}
const int mod = 1000000007 ;//998244353; //;
//const int N = 3e5, M = N;
vector<ll> dp;
void solve()
{
ll n, m;
cin >> n >> m;
ll ans = 0;
while (n > 0)
{
ll t = n % 10;
if (t + m >= 10)
{
ans = (ans + dp[m - (10 - t)]) % mod;
}
else
{
ans = (ans + 1) % mod;
}
// ans = (ans + f(n % 10, m)) % mod;
n /= 10;
}
cout << ans << endl;
// dp.clear();
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
int t = 1;
cin >> t;
dp.resize(200002, -1);
fo(i, 10)
dp[i] = 2;
dp[9] = 3;
Fo(i, 10, 200002)
{
dp[i] = (dp[i - 10] + dp[i - 9]) % mod;
}
while (t--) {
solve();
}
return 0;
}
| 9 |
CPP
|
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define fab(i,a,b) for(i=a;i<=b;i++)
#define fabr(i,a,b) for(i=b;i>=a;i--)
#define f(i,n) for(i=0;i<n;i++)
#define sc second
#define fr first
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define max 1000000000000000000
#define nl "\n"
using namespace std;
ll dp[200001];
void fun()
{
ll i;
f(i,200001)
{
if(i<=8)
dp[i]=2;
else if(i==9)
dp[i]=3;
else
dp[i]=(dp[i-9]+dp[i-10])%mod;
}
}
int main()
{
FAST;
ll t,i,m,z,u,ans,b,c,l,q,p,j,sum,d,n,a,x,y,k,w,h,r;
t=1;
char ch;
string s,aa,bb,dd,rr,tt,ss="";
fun();
cin>>t;
while(t--)
{
ans=0;
cin>>n>>m;
//cout<<dp[92]<<nl;
while(n>0)
{
k=n%10;
if(k+m<10)
ans+=1;
else
ans+=dp[k+m-10];
ans%=mod;
n=n/10;
}
cout<<ans<<nl;
}
return 0;
}
| 9 |
CPP
|
# Author : nitish420 --------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
def main():
mod=10**9+7
mm=200000
dp=[0 for _ in range(mm+1)]
dp[0]=2
dp[1]=2
for i in range(2,9):
dp[i]=2
dp[9]=3
for i in range(10,mm+1):
dp[i]=(dp[i-9]+dp[i-10])%mod
for _ in range(int(input())):
n,m=map(int,input().split())
ans=0
while n:
x=n%10
y=10-x
if y<=m:
ans=(ans+dp[m-y])%mod
else:
ans=(ans+1)%mod
n//=10
print(ans%mod)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b'\n') + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda: self.buffer.read().decode('ascii')
self.readline = lambda: self.buffer.readline().decode('ascii')
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# endregion
if __name__ == '__main__':
main()
| 9 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int mod = 1e9 + 7;
int dp[MAXN][10];
void solve()
{
for(int i = 0; i <= 9; i++)
{
dp[0][i] = 1;
}
for(int i = 1; i < MAXN; i++)
{
for(int j = 0; j <= 9; j++)
{
if(j == 9)
dp[i][j] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
else
dp[i][j] = dp[i - 1][j + 1];
}
}
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
solve();
int t, m, num;
cin >> t;
while(t--)
{
num = 0;
string str;
cin >> str >> m;
int z = str.size();
for(int i = 0; i < z; i++)
{
num += dp[m][str[i] - '0'] ;
num = num % mod;
}
cout << num << endl;
}
return 0;
}
| 9 |
CPP
|
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define debug(x) cout << #x << " is " << x << endl
typedef pair<int, int> pii;
typedef long long ll;
const int INF = 0x3f3f3f3f, N = 2e5 + 15;
const ll MOD = 1e9 + 7;
int t, n, m;
ll a[N];
int main()
{
for (int i = 0; i <= 9; ++i) a[i] = 1;
for (int i = 10; i <= N; ++i) a[i] = (a[i-9] + a[i-10]) % MOD;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
ll ans = 0;
while (n) {
(ans += a[n%10+m]) %= MOD;
n /= 10;
}
printf("%lld\n", ans);
}
return 0;
}
| 9 |
CPP
|
import sys
import io,os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def solve_tc(dp):
mod = 1000000000 + 7
n, m = map(int, input().split())
cnt = 0
while n > 0:
x = int(n % 10)
if m + x < 10:
cnt += 1
else:
cnt += dp[m + x - 10]
cnt = int(cnt % mod)
n //= 10
return str(cnt)
def dp_maker():
max_n = 200005
mod = 1000000007
dp = {}
for i in range(10):
dp[i] = 2
dp[9] = 3
for i in range(10, max_n):
dp[i] = (dp[i - 9] + dp[i - 10]) % mod
return dp
dp = dp_maker()
t = int(input())
while t > 0:
t -= 1
sys.stdout.write(solve_tc(dp))
sys.stdout.write("\n")
| 9 |
PYTHON3
|
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
#define rep(i,j,n) for(int i=(j);i<=((int)n);++i)
#define rev(i,n,j) for(int i=(n);i>=((int)j);--i)
typedef long long int ll;
#define int long long int
const ll INFL=0x3f3f3f3f3f3f3f3fLL;
const int INF=0x3f3f3f3f;
const int mod=1000000007;
#define endl "\n"
#define mem(a,val) memset(a,val,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define pb push_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define readmat(a, n, m) int a[n + 5][m + 5] = {}; rep(i, 1, n) {rep(j, 1, m) cin >> a[i][j];}
#define printmat(a, n, m) rep (i, 1, n) {rep (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define printarr(a, n) rep(i, 1, n) cout << a[i] << " "; cout << endl;
typedef std::map< int,int> mii;
typedef std::vector< int > vi;
typedef std::vector< vi > vvi;
typedef std::pair< int,int > ii;
using namespace std;
#define cerr cout
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << *it << " = " << a << endl;
err(++it, args...);}
const int N = 2e5+5, M = 2e5;
vector <int>g[N];
int dp[15][N];
void pre()
{
for(int i = 0; i <10; ++i)
{
int cnt[11]={0};
int ncnt[11]={0};
cnt[i]=1;
for(int j = 1; j <=M; ++j)
{
for(int k = 0; k <10; ++k)
{
ncnt[k]=0;
}
for(int k = 0; k <10; ++k)
{
if (k!=9)
{
ncnt[k+1]=(cnt[k]%mod);
}
else
{
ncnt[0]=(ncnt[0]+cnt[k])%mod;
ncnt[1]=(ncnt[1]+cnt[k])%mod;
}
}
int s=0;
for(int k = 0; k <10; ++k)
{
cnt[k]=(ncnt[k]%mod);
s=(s+cnt[k])%mod;
}
dp[i][j]=s;
}
}
}
void solve()
{
string n;
int m;
cin>>n>>m;
mii x;
for(auto &i : n)
{
x[i-'0']++;
}
int ans=0;
for(auto &[i,j] : x)
{
ans=(ans+(dp[i][m]*j)%mod)%mod;
}
cout<<ans<<endl;
}
signed main()
{
FAST;
#ifdef LOCAL
freopen("C:\\Users\\hp\\Documents\\input.txt", "r", stdin);
freopen("C:\\Users\\hp\\Documents\\output.txt", "w", stdout);
std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
start = std::chrono::high_resolution_clock::now();
#endif
pre();
int t;
cin>>t;
while(t--)
{
solve();
}
#ifdef LOCAL
end = std::chrono::high_resolution_clock::now();
ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
cout<<endl;
cout << "\nElapsed Time: " << elapsed_time << "ms\n";
#endif
return 0;
}
// vector string set map first second continue break return upper_bound lower_bound length void sort
// stack queue pop size erase empty insert
// #Hala BBCF
| 9 |
CPP
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 1000000007
#define vi vector<int>
#define vl vector<long long>
#define pi pair<int,int>
#define pl pair<long long,long long>
#define pb push_back
#define mi map<int,int>
#define ml map<long long,long long>
ll dp[10][200001];
ll a[10];
ll b[10];
void makedp()
{
ll i,j,ii,sz=0;
for(i=0;i<10;i++)
{
dp[i][0]=1;
}
for(i=0;i<10;i++)
{
sz=1;
for(j=0;j<10;j++){a[j]=0;b[j]=0;}
a[i]=1;
for(j=1;j<=200000;j++)
{
for(ii=0;ii<10;ii++)
{
if(ii==9)
{
sz+=a[ii];b[0]+=a[ii];b[1]+=a[ii];a[ii]=0;
}
else
{
b[ii+1]+=a[ii];a[ii]=0;
}
}
dp[i][j]=sz;
for(ii=0;ii<10;ii++)
{
a[ii]=b[ii];
a[ii]=a[ii]%MAX;
b[ii]=0;
}
}
}
// for(i=0;i<=20;i++)
// {
// cout<<dp[1][i]<<" ";
// }
// printf("\n");
}
int main()
{
makedp();
int t;scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d %d",&n,&m);
ll s=0;
while(n)
{
//cout<<dp[n%10][m]<<" ";
s+=dp[n%10][m];
s=s%MAX;
n/=10;
}
printf("%lld\n",s%MAX);
}
return 0;
}
| 9 |
CPP
|
import sys
input = sys.stdin.readline
M = 10 ** 9 + 7
dp = [[0, 0] for i in range(200001)]
for i in range(200001):
if i < 10:
dp[i][0] = 1
dp[i][1] = 1
if i == 9:
dp[i][1] = dp[1][1] + dp[1][0]
else:
dp[i][0] = (dp[i - 10][1] + dp[i - 10][0]) % M
dp[i][1] = (dp[i - 9][1] + dp[i - 9][0]) % M
def solve(n, m):
s = list(str(n))
z = 0
for i in range(len(s)):
x = int(s[i])
if x + m < 10:
z += 1
else:
z += dp[m - (10 - x)][1] + dp[m - (10 - x)][0]
return str(z % M)
t = int(input())
o = []
while t > 0:
n, m = map(int, input().split())
o.append(solve(n, m))
t -= 1
print('\n'.join(o))
| 9 |
PYTHON3
|
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
template<typename T, typename U>
pair<T, U> operator+(const std::pair<T, U> &l, const std::pair<T, U> &r) {
return {l.first + r.first, l.second + r.second};
}
template<typename T, typename U>
pair<T, U> operator-(const std::pair<T, U> &l, const std::pair<T, U> &r) {
return {l.first - r.first, l.second - r.second};
}
const int N =2e5 + 10;
int dp[N][10];
int solve(int num , int m){
if(dp[m][num]!=-1){
return dp[m][num];
}
if(m==0){
return 1;
}
num++;
ll ans = 0;
if(num==10){
ans+=solve(1,m-1);
ans+=solve(0,m-1);
ans%=MOD;
}else{
ans=solve(num,m-1);
}
return dp[m][num-1] = ans;
}
int main() {
IO;
int t;
cin>>t;
memset(dp,-1,sizeof dp);
while (t--){
string str;
cin>>str;
int m ;
cin>>m ;
ll ans = 0 ;
for(char ch : str){
ans+=solve(ch-'0',m);
ans%=MOD;
}
cout<<ans<<endl;
}
}
| 9 |
CPP
|
def main():
import sys
input = sys.stdin.readline
MOD=10**9+7
t=int(input())
x=1
m=int(2*1e5+10)
dp= [1 for i in range(m+1) ]
for i in range(10,m+1):
dp[i]=(dp[i-10]+dp[i-9])%(MOD)
for _ in range(t):
n,k=map(int,input().split())
sums=0
while n:
sums = (sums+dp[k+n%10])
n = n//10
sums %=MOD
print(sums)
main()
| 9 |
PYTHON3
|
from sys import stdin
input = stdin.readline
mxn = 2 * (10 ** 5) + 15
mod = 10 ** 9 + 7
dp = [1] * mxn
for i in range(10, mxn):
dp[i] = (dp[i - 9] + dp[i - 10]) % mod
for test in range(int(input())):
n, k = map(int, input().strip().split())
ans = 0
for i in str(n):
ans = (ans + dp[k + int(i)]) % mod
print(ans)
| 9 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int max_n = 200005, mod = 1000000007;
int dp[max_n];
signed main(){
for(int i=0; i<9; i++)dp[i] = 2;
dp[9] = 3;
for(int i=10; i<max_n; i++){
dp[i] = (dp[i-9] + dp[i-10])%mod;
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
int n, m;
cin>>n>>m;
int ans = 0;
while(n > 0){
int x = n%10;
ans += ((m + x < 10) ? 1 : dp[m + x - 10]);
ans %= mod;
n/=10;
}
cout<<ans<<"\n";
}
return 0;
}
| 9 |
CPP
|
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
template <int M>
struct MInt {
unsigned int val;
MInt(): val(0) {}
MInt(long long x) : val(x >= 0 ? x % M : x % M + M) {}
static constexpr int get_mod() { return M; }
static void set_mod(int divisor) { assert(divisor == M); }
static void init(int x = 10000000) { inv(x, true); fact(x); fact_inv(x); }
static MInt inv(int x, bool init = false) {
// assert(0 <= x && x < M && std::__gcd(x, M) == 1);
static std::vector<MInt> inverse{0, 1};
int prev = inverse.size();
if (init && x >= prev) {
// "x!" and "M" must be disjoint.
inverse.resize(x + 1);
for (int i = prev; i <= x; ++i) inverse[i] = -inverse[M % i] * (M / i);
}
if (x < inverse.size()) return inverse[x];
unsigned int a = x, b = M; int u = 1, v = 0;
while (b) {
unsigned int q = a / b;
std::swap(a -= q * b, b);
std::swap(u -= q * v, v);
}
return u;
}
static MInt fact(int x) {
static std::vector<MInt> f{1};
int prev = f.size();
if (x >= prev) {
f.resize(x + 1);
for (int i = prev; i <= x; ++i) f[i] = f[i - 1] * i;
}
return f[x];
}
static MInt fact_inv(int x) {
static std::vector<MInt> finv{1};
int prev = finv.size();
if (x >= prev) {
finv.resize(x + 1);
finv[x] = inv(fact(x).val);
for (int i = x; i > prev; --i) finv[i - 1] = finv[i] * i;
}
return finv[x];
}
static MInt nCk(int n, int k) {
if (n < 0 || n < k || k < 0) return 0;
if (n - k > k) k = n - k;
return fact(n) * fact_inv(k) * fact_inv(n - k);
}
static MInt nPk(int n, int k) { return n < 0 || n < k || k < 0 ? 0 : fact(n) * fact_inv(n - k); }
static MInt nHk(int n, int k) { return n < 0 || k < 0 ? 0 : (k == 0 ? 1 : nCk(n + k - 1, k)); }
static MInt large_nCk(long long n, int k) {
if (n < 0 || n < k || k < 0) return 0;
inv(k, true);
MInt res = 1;
for (int i = 1; i <= k; ++i) res *= inv(i) * n--;
return res;
}
MInt pow(long long exponent) const {
MInt tmp = *this, res = 1;
while (exponent > 0) {
if (exponent & 1) res *= tmp;
tmp *= tmp;
exponent >>= 1;
}
return res;
}
MInt &operator+=(const MInt &x) { if((val += x.val) >= M) val -= M; return *this; }
MInt &operator-=(const MInt &x) { if((val += M - x.val) >= M) val -= M; return *this; }
MInt &operator*=(const MInt &x) { val = static_cast<unsigned long long>(val) * x.val % M; return *this; }
MInt &operator/=(const MInt &x) { return *this *= inv(x.val); }
bool operator==(const MInt &x) const { return val == x.val; }
bool operator!=(const MInt &x) const { return val != x.val; }
bool operator<(const MInt &x) const { return val < x.val; }
bool operator<=(const MInt &x) const { return val <= x.val; }
bool operator>(const MInt &x) const { return val > x.val; }
bool operator>=(const MInt &x) const { return val >= x.val; }
MInt &operator++() { if (++val == M) val = 0; return *this; }
MInt operator++(int) { MInt res = *this; ++*this; return res; }
MInt &operator--() { val = (val == 0 ? M : val) - 1; return *this; }
MInt operator--(int) { MInt res = *this; --*this; return res; }
MInt operator+() const { return *this; }
MInt operator-() const { return MInt(val ? M - val : 0); }
MInt operator+(const MInt &x) const { return MInt(*this) += x; }
MInt operator-(const MInt &x) const { return MInt(*this) -= x; }
MInt operator*(const MInt &x) const { return MInt(*this) *= x; }
MInt operator/(const MInt &x) const { return MInt(*this) /= x; }
friend std::ostream &operator<<(std::ostream &os, const MInt &x) { return os << x.val; }
friend std::istream &operator>>(std::istream &is, MInt &x) { long long val; is >> val; x = MInt(val); return is; }
};
namespace std { template <int M> MInt<M> abs(const MInt<M> &x) { return x; } }
using ModInt = MInt<MOD>;
constexpr int M = 200000;
ModInt dp[10][M + 1]{};
void solve() {
string n; int m; cin >> n >> m;
ModInt ans = 0;
for (char c : n) ans += dp[c - '0'][m];
cout << ans << '\n';
}
int main() {
REP(i, 10) dp[i][0] = 1;
FOR(j, 1, M + 1) REP(i, 10) {
for (char c : to_string(i + 1)) dp[i][j] += dp[c - '0'][j - 1];
}
int t; cin >> t;
while (t--) solve();
return 0;
}
| 9 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
//define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x <<'\t' << x <<endl
#else
#define debug(x)
#endif
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
#define lowbit(x) ((x) & -(x))
#define mem(a, b) memset(a, b, sizeof(a))
#define PI acos(-1)
#define endl '\n'
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
//#define int long long
//ll gcd(ll a, ll b){a = abs(a);b = abs(b);return a == 0 ? b : gcd(b % a, a);}
//inline ll Pow(ll a, ll n, ll MOD) { ll t = 1; a %= MOD; while (n > 0) { if (n & 1) t = t * a % MOD; a = a * a % MOD, n >>= 1; } return t % MOD; }
#define int long long
const int maxn = 2e5+100;
int a[20][maxn];
ll solve(int x,int m)
{
if(a[x][m]!=-1) return a[x][m];
if(x+m<10) return 1;
ll res = 0;
res += solve(1,m-(10-x));
res %= mod;
res += solve(0,m-(10-x));
res %= mod;
return a[x][m] = res;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
fast;
int T;
cin>>T;
mem(a,-1);
while(T--){
int n,m;
cin>>n>>m;
ll res = 0;
while(n){
res += solve(n%10,m);
res = res%mod;
n /= 10;
}
cout<<res<<endl;
}
return 0;
}
| 9 |
CPP
|
#include<bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>
#define ull unsigned long long int
//#define lli long long int
#define int long long int
#define NUM 1000000007
#define mp make_pair
#define pb push_back
#define ITR ::iterator
#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
//ull power(ull x, ull n) {
// if (n == 0)
// return 1;
//
// if (n % 2 == 0) {
// ull y = power(x, n / 2);
// return (y * y);
// }
// else return ((x * pow(x, n - 1)));
//}
int fact(int n)
{
int ans = 1;
while (n)
{
ans = (ans * n) % NUM;
n--;
}
return ans;
}
const int maxn = 2e5 + 1;
int dp[10][maxn];
int rec(int n, int m)
{
if (m <= 0 or m < (10 - n)) return 1;
if (dp[n][m] != -1) return dp[n][m];
if (n + m >= 10) return dp[n][m] = (rec(1, m - 10 + n) + rec(0, m - 10 + n)) % NUM;
return dp[n][m];
}
signed main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
fast_io
int t;
cin >> t;
vector<int> v;
memset(dp, -1, sizeof dp);
while (t--) {
v.clear();
int i, n, m, ans = 0;
cin >> n >> m;
while (n)
{
ans += rec(n % 10, m);
n /= 10;
ans %= NUM;
}
cout << ans << endl;
}
return 0;
}
| 9 |
CPP
|
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MAXM 200015
long long y;
int pd[MAXM];
int solve(int x){
if(x < 0) return 0;
if(pd[x] == -1){
if(x <= 9) pd[x] = 1;
else{
y = (solve(x - 10) + solve(x - 9));
if(y > MOD) y -= MOD;
pd[x] = y;
}
}
return pd[x];
}
int main(){
int t; scanf("%d", &t);
memset(pd, -1, sizeof pd);
solve(MAXM - 1);
while(t--){
char n[10]; scanf("%s", n);
int m; scanf("%d", &m);
long long ans = 0;
for(int i = 0; n[i]; ++i){
int z = n[i] - '0';
ans += solve(m + z);
ans %= MOD;
}
printf("%lld\n", ans);
}
}
| 9 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
//typedef unsigned long long int ull;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector<vector<ll>> v(10,vector<ll> (200001,0));
ll A[10];ll B[10] = {0};
ll maxx = 200000;
for(int I=0;I<10;++I){
for(int j=0;j<10;++j){
if(j==I)A[j] = 1;
else A[j]=0;
}
for(ll k=0;k<maxx;++k){
for(int i=0;i<10;++i){
if(i==0)B[0] = (A[9])%mod;
else if(i==1)B[1] = (A[0] + A[9])%mod;
else B[i] = (A[i-1])%mod;
}
ll count =0;
for(int i=0;i<10;++i){A[i] = B[i];count = (count + A[i])%mod;}
v[I][k+1] = count;
}
}
int t=1;cin>>t;
while(t--){
string s;ll m;
cin>>s>>m;
ll ans = 0;
for(int i=0;i<(int)s.length();++i){
ans = (ans + v[s[i]-'0'][m])%mod;
}
//cout<<"here ";
cout<<ans<<endl;
/*
ll a[10] = {0}, b[10] = {0};
for(int i=0;i<(int)s.length();++i){
a[s[i]-'0']++;
}
//for(int i=0;i<10;++i)cout<<a[i]<<" ";
while(m--){
for(int i=0;i<10;++i){
if(i==0)b[0] = (a[9])%mod;
else if(i==1)b[1] = (a[0] + a[9])%mod;
else b[i] = (a[i-1])%mod;
}
for(int i=0;i<10;++i)a[i] = b[i];
}
ll ans = 0;
for(int i=0;i<10;++i){
ans = (ans + a[i])%mod;
}
//cout<<"here ";
cout<<ans<<endl;
*/
}
return 0;
}
| 9 |
CPP
|
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
ll mod=1000000007;
using namespace std;
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll dp[10][200001];
//ll dp[200001][10];
// void calc()
// {
// for(int i=0;i<=9;i++) dp[0][i]=1;//base case
// for(int i=1;i<=200000;i++)
// {
// for(int j=0;j<9;j++)
// dp[i][j]=dp[i-1][j+1];
// dp[i][9]=(dp[i-1][1]+dp[i-1][0])%mod;
// }
// }
ll fun(ll n,ll m)
{
//cout<<"Tej ";
if(m==0) return 1;
if(dp[n][m]!=-1) return dp[n][m];
if(n==9)
dp[n][m]=fun(1,m-1)+fun(0,m-1);
else
dp[n][m]=fun(n+1,m-1);
return dp[n][m]%mod;
}
void solve()
{
ll n,m;
cin>>n>>m;
ll ans=0;
while(n)
{
ans=(ans + fun(n%10,m))%mod;
n/=10;
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
memset(dp,-1,sizeof(dp));
//calc();
int t=1;cin>>t;
while(t--)
{
solve();
}
return 0;
}
| 9 |
CPP
|
#include<bits/stdc++.h>
using namespace std;
#define long long long
#define fi first
#define se second
const long MOD = 1e9+7;
const long LINF = 1e18;
const long INF = 1e9;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
int D[10][200003][10];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("input.in", "r", stdin);
for(int i = 0; i < 10; i++)
D[i][0][i] = 1;
for(int i = 0; i < 10; i++)
{
for(int j = 0; j <= 199999; j++)
{
for(int k = 0; k <= 8; k++)
D[i][j+1][k+1] = (D[i][j+1][k+1]+D[i][j][k])%MOD;
D[i][j+1][1] = (D[i][j+1][1]+D[i][j][9])%MOD;
D[i][j+1][0] = (D[i][j+1][0]+D[i][j][9])%MOD;
}
}
int t; cin >> t;
while(t--)
{
string s; cin >> s;
int k; cin >> k;
int res = 0;
for(char c : s)
{
int x = c-'0';
for(int i = 0; i <= 9; i++)
res = (res+D[x][k][i])%MOD;
}
cout << res << "\n";
}
}
| 9 |
CPP
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char a[20];
ll dp[200020];
ll cnt1[10];
ll cnt2[10];
ll mod=1e9+7;
int main()
{
cnt1[0]=1;
for(int i=1;i<=9;i++){
cnt1[i]=0;
}
dp[0]=1;
for(int i=1;i<200020;i++){
if(i%2==1){
memset(cnt2,0,sizeof(cnt2));
}else{
memset(cnt1,0,sizeof(cnt1));
}
for(int j=0;j<9;j++){
if(i%2==1){
cnt2[j+1]=cnt1[j]%mod;
}else{
cnt1[j+1]=cnt2[j]%mod;
}
}
if(i%2==1){
cnt2[0]=(cnt2[0]+cnt1[9])%mod;
cnt2[1]=(cnt2[1]+cnt1[9])%mod;
}else{
cnt1[0]=(cnt1[0]+cnt2[9])%mod;
cnt1[1]=(cnt1[1]+cnt2[9])%mod;
}
ll sum=0;
for(int j=0;j<10;j++){
if(i%2==1){
sum=(sum+cnt2[j])%mod;
}else{
sum=(sum+cnt1[j])%mod;
}
}
dp[i]=sum%mod;
}
ll t;
scanf("%lld",&t);
while(t--){
ll n,m;
memset(a,'\0',sizeof(a));
scanf("%s%lld",a,&m);
ll sum=0;
for(int i=0;i<strlen(a);i++){
sum=(sum%mod+dp[a[i]-'0'+m]%mod)%mod;
}
printf("%lld\n",sum);
}
return 0;
}
| 9 |
CPP
|
#include<bits/stdc++.h>
using namespace std;
const int N = 300005;
const int mod = 1e9 + 7;
#define ll long long
#define rep(i, a, b) for(int i=(a);i<=(b);++i)
#define per(i, a, b) for(int i=(a);i>=(b);--i)
#define ms(a, b) memset(a, b, sizeof a)
int n, T, m;
ll f[N + 100];
int main(){
for(int i=0;i<=9;i++)f[i]=1;
for(int i=10;i<N;i++)f[i]=(f[i-10]+f[i-9])%mod;
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &m);
int ans = 0;
while(n)ans=(ans+f[m+n%10])%mod, n /= 10;
printf("%d\n", ans);
}
}
| 9 |
CPP
|
#include <bits/stdc++.h>
#define int long long int
#define F first
#define S second
#define MK make_pair
#define pb push_back
#define mid (l + r) / 2
using namespace std ;
const int N = 3e5 + 100 , M = 1e9 + 7;
int n , m , k , a[N] , f[10][N] , s[N] ;
int32_t main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cout << setprecision(30) << fixed ;
int ttt;
cin >> ttt;
f[0][0] = 1 ;
s[0] = 1 ;
for(int i = 1 ; i <= 3e5 ; i++){
f[0][i] = f[9][i - 1] ;
f[1][i] = f[0][i - 1] + f[9][i - 1];
f[2][i] = f[1][i - 1] ;
f[3][i] = f[2][i - 1] ;
f[4][i] = f[3][i - 1] ;
f[5][i] = f[4][i - 1] ;
f[6][i] = f[5][i - 1] ;
f[7][i] = f[6][i - 1] ;
f[8][i] = f[7][i - 1] ;
f[9][i] = f[8][i - 1] ;
f[1][i] %= M ;
f[1][i] %= M ;
f[2][i] %= M ;
f[3][i] %= M ;
f[4][i] %= M ;
f[5][i] %= M ;
f[6][i] %= M ;
f[7][i] %= M ;
f[8][i] %= M ;
f[9][i] %= M ;
s[i] = s[i - 1] + f[9][i - 1] ;
s[i] %= M ;
}
while(ttt--){
cin >> n >> m;
int ans = 0 ;
while(n){
int x = (n % 10) ;
ans += s[x + m] ;
n /= 10 ;
}
ans %= M ;
cout << ans << '\n' ;
}
}
/*
#include <radman/roderc++.h>
....._____
.~~~~~////////\\ ...
.:::::////////////\\ ....::////////.. (/\\\\...
.:::::////// \\\\///\\ .::::// ..:::::///////////////. \\\\\$$$$$$
\\\\\////// \\\\///\\ //\\\////// \\\\\////////////////////. ""\\$$$$$$$
\\\\\//// \\\\//// |||||////////. \\\\\///// ~~~~~////// ... "\$$$$
\\\\\//\ ////|||/ \\\\\///////// \\\\\//\ ~~~~~////// (/\\\\... .
\\\\\//\ ////|||/ |||||////*\\///. \\\\\//\ ~~~~~////// \\\\\$$$$$$ .@@@@@.
\\\\\//\ ////|||/ \\\\\///|\\\//// \\\\\//\ ~~~~~////// ""\\$$$$$$$ @@@@////\
\\\\\//\ ____---/|||/ |||||///|\\\\\///. \\\\\//\ ~~~~~////// "\$$$$ @@@@\///\
\\\\\//\--|||||||_-' \\\\\///|\\\\\//// \\\\\//\ ~~~~~////// ,@@@@|///|
\\\\\//\|||||_"-\\\\\ |||||///| ~~~~~///. \\\\\//\ ~~~~~////// .@@@@. /@@@@@|/////
\\\\\//\///"""\\\\\\\\ \\\\\///|~~~~[[[////. \\\\\//\ ~~~~~////// @@@@@@@@ ..@@@@@.//////
\\\\\//\ \"""\\\\\\\ |||||///|~~[[[[["\////. \\\\\//\ ~~~~~////// '@@@@/////\ .:;@@@@@@@..///////"
\\\\\//\ \"""\\\\\\ \\\\\///|[[[[*\\\\\////. \\\\\//\ ~~~~~////// *@@@\//////\@@@@@@@@..//////////"
\\\\\//\ \:::\\\\/ |||||///|[[[* \\\\\\/// \\\\\//\~~~~~///////' *@@\/////////////////////"
\\\\\//\ \___\\/ \\\\\///|* \\\\\/" \\\\\//\~~////////' **"///////////"""
\\\\\//\ |||||///| \\\\\//\///////"
\\\\\//\ \\\\\///| \\\\\//\////"
\\\\\/// |||||////| \\\\\////"
\\\\\/" \\\\\///* \\\\\/"
"""""*
*/
| 9 |
CPP
|
//#pragma GCC optimize("Ofast,fast-math,unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt")
#include <bits/stdc++.h>
//#define int32_t int64_t
/*
const size_t MAX_MEM = 2e8;
char MEM[MAX_MEM];
size_t MEM_POS = 0;
void* operator new(size_t x) {
auto ret = MEM + MEM_POS;
MEM_POS += x;
assert(MEM_POS < MAX_MEM);
return ret;
}
void operator delete(void*)
{}
*/
template <class T>
std::istream& operator>>(std::istream &in, std::vector<T> &a) {
for (auto &x : a)
in >> x;
return in;
}
template <class T>
std::ostream& operator<<(std::ostream &out, const std::vector<T> &a) {
for (auto &x : a)
out << x << " ";
return out;
}
template <class T, class U>
std::istream& operator>>(std::istream &in, std::pair<T, U> &p) {
in >> p.first >> p.second;
return in;
}
template <class T, class U>
std::ostream& operator<<(std::ostream &out, const std::pair<T, U> &p) {
out << p.first << " " << p.second;
return out;
}
const int64_t P = 1e9+7;
int64_t add(int64_t a, int64_t b) {
return a + b >= P ? a + b - P : a + b;
}
int64_t mul(int64_t a, int64_t b) {
return a * b % P;
}
const int64_t M = 2e5+5, D = 10;
std::vector<std::vector<int64_t>> dp(M, std::vector<int64_t>(D));
void init() {
for (int i = 0; i < D; ++i)
dp[0][i] = 1;
for (int l = 1; l < M; ++l) {
for (int d = 0; d < D; ++d) {
if (d == 9) {
dp[l][d] = add(dp[l - 1][0], dp[l - 1][1]);
} else {
dp[l][d] = dp[l - 1][d + 1];
}
}
}
}
void solve() {
int64_t m;
std::string n;
std::cin >> n >> m;
std::reverse(n.begin(), n.end());
while (n.size() > 1 && n.back() == '0')
n.pop_back();
std::reverse(n.begin(), n.end());
int64_t ans = 0;
for (char d : n)
ans = add(ans, dp[m][d - '0']);
std::cout << ans << "\n";
}
signed main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
init();
int32_t t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
| 9 |
CPP
|
import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import itertools
import bisect
import heapq
#sys.setrecursionlimit(100000)
#^^^TAKE CARE FOR MEMORY LIMIT^^^
def main():
pass
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def binary(n):
return (bin(n).replace("0b", ""))
def decimal(s):
return (int(s, 2))
def pow2(n):
p = 0
while (n > 1):
n //= 2
p += 1
return (p)
def primeFactors(n):
l = []
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
l.append(i)
n = n / i
if n > 2:
l.append(int(n))
return (l)
def isPrime(n):
if (n == 1):
return (False)
else:
root = int(n ** 0.5)
root += 1
for i in range(2, root):
if (n % i == 0):
return (False)
return (True)
def maxPrimeFactors(n):
maxPrime = -1
while n % 2 == 0:
maxPrime = 2
n >>= 1
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
maxPrime = i
n = n / i
if n > 2:
maxPrime = n
return int(maxPrime)
def countcon(s, i):
c = 0
ch = s[i]
for i in range(i, len(s)):
if (s[i] == ch):
c += 1
else:
break
return (c)
def lis(arr):
n = len(arr)
lis = [1] * n
for i in range(1, n):
for j in range(0, i):
if arr[i] > arr[j] and lis[i] < lis[j] + 1:
lis[i] = lis[j] + 1
maximum = 0
for i in range(n):
maximum = max(maximum, lis[i])
return maximum
def isSubSequence(str1, str2):
m = len(str1)
n = len(str2)
j = 0
i = 0
while j < m and i < n:
if str1[j] == str2[i]:
j = j + 1
i = i + 1
return j == m
def maxfac(n):
root = int(n ** 0.5)
for i in range(2, root + 1):
if (n % i == 0):
return (n // i)
return (n)
def p2(n):
c=0
while(n%2==0):
n//=2
c+=1
return c
def seive(n):
primes=[True]*(n+1)
primes[1]=primes[0]=False
for i in range(2,n+1):
if(primes[i]):
for j in range(i+i,n+1,i):
primes[j]=False
p=[]
for i in range(0,n+1):
if(primes[i]):
p.append(i)
return(p)
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den,
p - 2, p)) % p
def denofactinverse(n,m):
fac=1
for i in range(1,n+1):
fac=(fac*i)%m
return (pow(fac,m-2,m))
def numofact(n,m):
fac=1
for i in range(1,n+1):
fac=(fac*i)%m
return(fac)
def sod(n):
s=0
while(n>0):
s+=n%10
n//=10
return s
dp=[2]*9
dp+=[3]
mod=1000000007
for i in range(10,2*(10**5)+1):
dp.append((dp[i-9]+dp[i-10])%mod)
#print(dp[-1])
for xyz in range(0,int(input())):
n,m=map(int,input().split())
ans=0
while(n>0):
num=n%10
n//=10
if(num+m<10):
ans+=1
ans=ans%mod
else:
tm=m-(10-num)
ans+=dp[tm]
ans=ans%mod
print(ans)
| 9 |
PYTHON3
|
#include<iostream>
#include<stack>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<functional>
#include<limits.h>
#include<utility>
#include<queue>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<bitset>
#include<time.h>
#include<unordered_map>
#define lowbit(x) ((x)&(-x))
typedef long long ll;
typedef long double ld;
using namespace std;
//
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9+7;
const double eps = 1e-7;
typedef pair<ll, ll> pii;
int dir[4][2] = { {0,1},{0,-1},{-1,0},{1,0} };
ll dp[10][maxn];
ll dfs(int now, int re)
{
if (re == 0) return 1;
if (dp[now][re]) return dp[now][re];
ll ans = 0;
if (now + re >= 10)
{
ans = dfs(1, re - 10 + now) + dfs(0, re - 10 + now);
ans %= mod;
}
else
ans = dfs(now + re, 0);
return dp[now][re] = ans;
}
string s;
int m;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--)
{
cin >> s >> m;
ll ans = 0;
for (int i = 0; i < s.size(); i++)
ans += dfs(s[i] - '0', m), ans %= mod;
cout << ans << endl;
}
return ~~(0 - 0);
}
| 9 |
CPP
|
from sys import stdin,stdout
dp=[]
M=10**9+7
for i in range(200011):
if i<10:
dp.append(1)
else:
dp.append((dp[i-9]+dp[i-10])%M)
for _ in range(int(input())):
n,m=stdin.readline().split()
m=int(m)
M=10**9+7
ans=0
for i in n:
ans=(ans+dp[m+int(i)])%M
print(ans)
| 9 |
PYTHON3
|
from sys import stdin, stdout
dp = [0] * 200005
for i in range(0, 9):
dp[i] = 2
dp[9] = 3
for i in range(10, 200005):
dp[i] = (dp[i-10] + dp[i-9]) % 1000000007
ans = ''
for i in range(int(input())):
n, m = stdin.readline().split()
m = int(m)
res = 0
for s in n:
s = int(s)
ind = m - (10-s)
if ind < 0:
res += 1
continue
res = (res + dp[ind]) % 1000000007
stdout.write(str(res) + "\n")
| 9 |
PYTHON3
|
import sys
input = sys.stdin.readline
MOD=(1e9)+7
t=int(input())
m=int(2*1e5+11)
dp= [1 for i in range(m+1) ]
for i in range(10,m+1):
dp[i]=(dp[i-10]+dp[i-9])%(MOD)
for _ in range(t):
n,k=map(int,input().split())
sums=0
while n:
sums = (sums+dp[k+n%10])
n = n//10
sums %=MOD
print(int(sums))
| 9 |
PYTHON3
|
import sys
input = sys.stdin.readline
dp = []
M = 10 ** 9 + 7
for i in range(200011):
if i < 10:
dp.append(1)
else:
dp.append((dp[i - 9] + dp[i - 10]) % M)
for _ in range(int(input())):
n, m = input().split()
m = int(m)
ans = 0
for i in n:
ans = (ans + dp[m + int(i)]) % M
print(ans)
| 9 |
PYTHON3
|
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M = 1e9+7;
ll mod(ll x){
return (x%M + M)%M;
}
ll mul(ll a, ll b){
return mod((mod(a)*mod(b)));
}
ll add(ll a , ll b){
return mod(mod(a)+mod(b));
}
void solve(){
vector<vector<int>>dp(200001,vector<int>(10));
for(int i=0;i<10;i++) dp[0][i]=1;
for(int i=1;i<=200000;i++){
for(int j=0;j<10;j++){
if(j<=8) dp[i][j]=dp[i-1][j+1];
else dp[i][j]=add(dp[i-1][0],dp[i-1][1]);
}
}
int t;
cin>>t;
while(t--){
string s;
cin>>s;
int m;
cin>>m;
vector<int>f(10,0);
for(auto i : s) f[i-'0']++;
ll ans=0;
for(int i=0;i<10;i++){
ans=add(ans,mul(f[i],dp[m][i]));
}
cout<<ans<<"\n";
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout<<fixed;
cout<<setprecision(10);
// freopen("timber_input.txt", "r", stdin);
// freopen("timber_output.txt", "w", stdout);
int t=1;
// cin>>t;
for(int i=1;i<=t;i++){
// cout<<"Case #"<<i<<": ";
solve();
}
return 0;
}
| 9 |
CPP
|
import os
import sys
from io import BytesIO, IOBase
def main():
mod = 10 ** 9 + 7
mm = 200000
dp = [0 for _ in range(mm + 1)]
dp[0] = 2
dp[1] = 2
for i in range(2, 9):
dp[i] = 2
dp[9] = 3
for i in range(10, mm + 1):
dp[i] = (dp[i - 9] + dp[i - 10]) % mod
for _ in range(int(input())):
n, m = map(int, input().split())
ans = 0
while n:
x = n % 10
y = 10 - x
if y <= m:
ans = (ans + dp[m - y]) % mod
else:
ans = (ans + 1) % mod
n //= 10
print(ans % mod)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b'\n') + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda: self.buffer.read().decode('ascii')
self.readline = lambda: self.buffer.readline().decode('ascii')
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# endregion
if __name__ == '__main__':
main()
| 9 |
PYTHON3
|
import sys
input = sys.stdin.readline
t = int(input().strip())
M = 1000000007
dp = [0] * (2 * 100000+20)
dp[:10] = list(1 for i in range(10))
for i in range(10, 2*100000+20):
dp[i] = dp[i-9] + dp[i-10]
dp[i] %= M
while t:
t -= 1
n, m = map(int, input().strip().split())
n = str(n)
result = 0
for i in n:
result += dp[int(i)+m]
result %= M
print(result)
| 9 |
PYTHON3
|
# Author: yumtam
# Created at: 2021-04-29 12:58
MOD = 10**9 + 7
a = []
c = [1] + [0]*9
for _ in range(2 * 10**5 + 50):
a.append(sum(c))
d = [0] * 10
for i in range(9):
d[i+1] = c[i]
d[0] = (d[0] + c[9]) % MOD
d[1] = (d[1] + c[9]) % MOD
c = d
import sys, os, io
input = lambda: sys.stdin.readline().rstrip('\r\n')
stdout = io.BytesIO()
sys.stdout.write = lambda s: stdout.write(s.encode("ascii"))
for _ in range(int(input())):
n, k = [int(t) for t in input().split()]
s = str(n)
c = [s.count(str(i)) for i in range(10)]
ans = 0
for i in range(10):
ans = (ans + c[i] * a[i+k]) % MOD
print(ans)
os.write(1, stdout.getvalue())
| 9 |
PYTHON3
|
# main.py
# Code Jam only
# import numpy as np
# import scipy as sp
import sys
# import itertools
# import functools
# import math
input = sys.stdin.readline
mod = pow(10, 9) + 7
arr = [0]*(200020)
for i in range(10):
arr[i] = 1
for i in range(10, 200020):
arr[i] = (arr[i-10] + arr[i-9])%mod
def solve():
n, m = map(int, input().split(' '))
ans = 0
while True:
k = m + n%10
ans += arr[k]
n = n//10
if n == 0:
break
print(ans%mod)
if __name__ == "__main__":
for t in range(int(input())):
# print(f"Case #{t+1}: {solve()}")
solve()
| 9 |
PYTHON3
|
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
class Solution:
def __init__(self):
#self.cache = {}
self.mod = 10**9 + 7
N = 2 * 10**5 + 1
self.dp = [1] * N
for i in range(10,N):
self.dp[i] = (self.dp[i-10] + self.dp[i-9]) % self.mod
def getLen(self, x):
while x >= len(self.dp):
self.dp.append((self.dp[-10] + self.dp[-9]))
return self.dp[x]
def solve(self, n, m):
ans = 0
while n > 0:
dig = n % 10
n //= 10
ans = (ans + self.getLen(dig + m)) % self.mod
return ans
s = Solution()
numCases = int(input())
for i in range(1, numCases+1):
n, m = map(int,input().split())
ans = s.solve(n, m)
print("%d" % ans)
| 9 |
PYTHON3
|
// Problem: C. Add One
// Contest: Codeforces - Divide by Zero 2021 and Codeforces Round #714 (Div. 2)
// URL: https://codeforces.com/contest/1513/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<iostream>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int N = 2e5+10;
const int mod = 1e9+7;
long long a[15];
long long b[N];
void init(){
for(int i = 0; i <= 8; i ++) b[i] = 2;
b[9]=3;
for(int i = 10; i <=200005;i++) b[i] = (b[i-9]+b[i-10])%mod;
}
void solve(long long m,long long n){
for(int i = 0; i <=9;i ++) a[i] = 0;
// long long n, m;
// cin >> n >> m;
long long ans = 0;
if(n==0) {
a[0]++;
}
while(n){
a[n%10]++;
n/=10;
}
for(int i = 0; i <=9; i ++){
long long x;
if(m-10+i<0) x = 1;
else x = b[m-10+i];
long long temp = (a[i]*x)%mod;
ans+=temp;
ans%=mod;
}
printf("%lld\n",ans);
return;
}
int main(){
int T;
cin >> T;
init();
while (T--){
long long n, m;
scanf("%lld %lld",&n,&m);
solve(m,n);
}
// for(int i = 0; i <= 100; i ++){
// cout <<"i="<<i<<"----";
// solve(i,10);
// }
return 0;
}
| 9 |
CPP
|
from sys import stdin
dp=[0]*(2*10**5+1)
for i in range(9):
dp[i]=2
dp[9]=3
for i in range(10,2*10**5+1):
dp[i]=(dp[i-9]+dp[i-10])%(10**9+7)
for _ in range(int(input())):
n,m=map(int,stdin.readline().split())
n=str(n)
a=[0]*len(n)
ans=0
for i in n:
temp=int(i)+m
if temp<10:
ans+=1
else:
ans+=dp[m+int(i)-10]%(10**9+7)
print((ans)%(10**9+7))
| 9 |
PYTHON3
|
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ifs freopen("aa.in","r",stdin);
#define ofs freopen("aa.out","w",stdout);
#define iof ifs ofs
#define ll long long
#define ld long double
#define da(x,i) cout << #x << "[" << i << "]=" << x[i] << "\n";
#define da2(x,i,y,j) cout << #x << "[" << i << "]=" << x[i] << " ! " << #y << "[" << j << "]=" << y[j] << "\n";
#define d2a(x,i,j) cout << #x << "[" << i << "][" << j << "]=" << x[i][j] << "\n";
#define db(x) cout << #x << "=" << (x) << "\n";
#define db2(x,y) cout << #x << "=" << (x) << " ! " << #y << "=" << (y) << "\n";
#define db3(x,y,z) cout << #x << "=" << (x) << " ! " << #y << "=" << (y) << " ! " << #z << "=" << (z) << "\n";
#define db4(w,x,y,z) cout << #w << "=" << (w) << " ! " << #x << "=" << (x) << " ! " << #y << "=" << (y) << " ! " << #z << "=" << (z) << "\n";
#define inf LLONG_MAX
#define fr first
#define sc second
#define all(a) a.begin(),a.end()
const ll N=2e5+70, M=1e9+7;
ll f[N];
ll tt,i,n,m,d,A;
string s;
int main()
{
fastio
for(i=0; i<10; i++)
f[i]=1;
for(i=10; i<N; i++)
f[i]=(f[i-10]+f[i-9])%M;
cin>>tt;
while(tt--){
cin>>n>>m;
for(i=n,A=0; i; i/=10){
d=i%10; d+=m;
A=(A+f[d]+M)%M;
}
cout<< A <<"\n";
}
}
| 9 |
CPP
|
//Bismillahir Rahmanir Raheem
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
ll dp[200001][11];
ll f(ll m,ll x){
if(m==0)return 0;
if(dp[m][x]!=-1)return dp[m][x];
dp[m][x]=0;
if(m>=(10-x)){
dp[m][x]=(1+(f(m-(10-x),0))%mod+(f(m-(10-x),1))%mod)%mod;
}
return dp[m][x];
}
int main()
{
fast;
memset(dp,-1,sizeof(dp));
f(200001,0);
f(200001,1);
int t;
cin>>t;
while(t--)
{
ll n,m;
string s;
cin>>s>>m;
ll ans=0;
n=s.size();
for(int i=0;i<n;i++){
ll v=s[i]-'0';
ans=(ans+1+f(m,v))%mod;
}
cout<<ans<<endl;
}
return 0;
}
| 9 |
CPP
|
#include "bits/stdc++.h"
using namespace std;
/*
find my code templates at https://github.com/galencolin/cp-templates
also maybe subscribe please thanks
*/
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL);}
#define f first
#define s second
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
cin >> p.first;
return cin >> p.second;
}
mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 rng(61378913);
/* usage - just do rng() */
void usaco(string filename) {
// #pragma message("be careful, freopen may be wrong")
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
// #include <atcoder/all>
// using namespace atcoder;
const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;
ll n, m, q, k, l, r, x, y, z;
const ll template_array_size = 1e6 + 15075;
ll a[template_array_size];
ll b[template_array_size];
ll c[template_array_size];
string s, t;
ll ans = 0;
ll dp[200005][11];
void solve(int tc = 0) {
cin >> s >> m;
ll ans = 0;
for (char c: s) ans = (ans + dp[m][c - '0']) % mod;
cout << ans << '\n';
}
int main() {
#ifdef galen_colin_local
auto begin = std::chrono::high_resolution_clock::now();
#endif
send help
#ifndef galen_colin_local
// usaco("code");
#endif
// usaco("cowland");
// freopen("tc.cpp", "r", stdin);
// freopen("tc2.cpp", "w", stdout);
cout << setprecision(15) << fixed;
memset(dp, 0, sizeof(dp));
for (ll i = 0; i < 10; i++) dp[0][i] = 1;
for (ll i = 1; i <= 200003; i++) {
for (ll j = 0; j < 9; j++) {
dp[i][j] = dp[i - 1][j + 1];
}
dp[i][9] = (dp[i - 1][1] + dp[i - 1][0]) % mod;
}
int tc = 1;
cin >> tc;
for (int t = 0; t < tc; t++) solve(t);
#ifdef galen_colin_local
auto end = std::chrono::high_resolution_clock::now();
cerr << setprecision(4) << fixed;
cerr << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl;
#endif
}
| 9 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const long long N=1e9+7;
#define int long long
#define pb push_back
#define f first
#define si second
#define mp make_pair
#define fastrack ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define PI 3.1415926535897
string alp="abcdefghijklmnopqrstuvwxyz";
signed main(){
fastrack;
int test=1;
cin>>test;
map<int,int>m[2];
int d[2][200007];
for(int i=0;i<2;i++){
for(int j=0;j<200007;j++){
d[i][j]=0;
}
}
for(int i=0;i<2;i++){
for(int j=0;j<10-i;j++){
d[i][j]=1;
}
m[i][10-i]=1;
d[i][10-i]=2;
for(int j=11-i;j<200007;j++){
d[i][j]+=(d[i][j-1]%N+m[i][j-9]%N+m[i][j-10]%N)%N;
d[i][j]%=N;
m[i][j]=N+(d[i][j])-(d[i][j-1]);
m[i][j]%=N;
}
}//cout<<d[9][200000]<<endl;
while(test--){
int n,m,x,ans=0;
cin>>n>>m;
int c[10]={};
while(n>0){
x=n%10;
c[x]++;
n/=10;
}
for(int i=0;i<10;i++){
if(i==0||i==1){
ans+=(c[i]*d[i][m])%N;
ans%=N;
}
else{
if(m>=10-i){
ans+=(c[i]*d[0][m-10+i])%N;
ans%=N;
ans+=(c[i]*d[1][m-10+i])%N;
ans%=N;
}
else if(c[i]){
ans+=c[i];
ans%=N;
}
}
//cout<<ans<<" ";
}//cout<<endl;
cout<<ans<<endl;
}
}
| 9 |
CPP
|
import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 25
MOD = pow(10, 9) + 7
BUFSIZE = 8192
from collections import defaultdict
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
dp=[0]*(2*pow(10,5))
for i in range(9):
dp[i]=2
dp[9]=3
for i in range(10, 2*pow(10,5)):
dp[i] = (dp[i-9]+dp[i-10])%MOD
for _ in range(int(input())):
n, m = map(int, input().split(" "))
ans = 0
while n:
x = n%10
if x + m < 10:
ans+=1
else:
ans += dp[x+m - 10]
ans%=MOD
n=n//10
print(ans)
| 9 |
PYTHON3
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.