Portals
are given a number of groups, the number n and a number a b
b is a decimal number to turn, find the 1 - n b are converted to the binary number and each of
Timeout version
#include <iostream>
#include <cstdio>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int n,b;
int change(int x){
int ans=0;
while(x){
ans+=x%b;
x/=b;
}
return ans;
}
int main(){
int t;
scanf("%d",&t);
rep(i,1,t+1){
scanf("%d%d",&n,&b);
int ans=0;
rep(i,1,n+1){
ans+=change(i);
}
printf("Case #%d: %d\n",i,ans);
}
return 0;
}
Play table thinking
For t enter the words, but the only answer to each value can be used to play table
#include <iostream>
#include <cstdio>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const int N=1e6+5;
int a[N][15];
int main(){
rep(i,2,11){
rep(j,1,N){
int t=j,cnt=0;
while(t){
cnt+=t%i;
t/=i;
}
a[j][i]=a[j-1][i]+cnt;
}
}
int t;
scanf("%d",&t);
rep(i,1,t+1){
int n,b;
scanf("%d%d",&n,&b);
printf("Case #%d: %d\n", i,a[n][b]);
}
return 0;
}