https://nanti.jisuanke.com/t/41422
Subject to the effect:
B and n are given, 1 to find n, the number of each band b and the sum of the respective digits.
Direct simulation of violence, TLE. .
I did not expect a fight table. . . Still too dishes.
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <string> 5 #include <math.h> 6 #include <algorithm> 7 #include <vector> 8 #include <stack> 9 #include <queue> 10 #include <set> 11 #include <map> 12 #include <math.h> 13 const int INF=0x3f3f3f3f; 14 typedef long long LL; 15 const int mod=1e9+7; 16 const int maxn=1e6+10; 17 using namespace std; 18 19 int c[11][maxn]; 20 21 int lowbit(int x) 22 { 23 return x&(-x); 24 } 25 26 void Update(int f,int n,int val) 27 { 28 while(n<maxn) 29 { 30 c[f][n]+=val; 31 n+=lowbit(n); 32 } 33 } 34 35 int Query(int f,int n) 36 { 37 int sum=0; 38 while(n>0) 39 { 40 sum+=c[f][n]; 41 n-=lowbit(n); 42 } 43 return sum; 44 } 45 46 void the init () // for establishing a binary tree for each array, the results of all decimal number from 2 to 10 full is calculated 47 { 48 for ( int I = 2 ; I <= 10 ; I ++ ) 49 { 50 for ( int J = . 1 ; J <MAXN; J ++ ) 51 is { 52 is int SUM = 0 ; 53 is int T = J; 54 is do { 55 SUM + = (T% I); 56 is T / = I; 57 is }while(t); 58 Update(i,j,sum); 59 } 60 } 61 } 62 63 int main() 64 { 65 int T; 66 scanf("%d",&T); 67 init();//打表 68 for(int k=1;k<=T;k++) 69 { 70 int n,b; 71 scanf("%d %d",&n,&b); 72 printf("Case #%d: %d\n",k,Query(b,n)); 73 } 74 return 0; 75 }