题意:https://nanti.jisuanke.com/t/41422

对每一位进行找循环节规律就行了。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
const double E=2.718281828;
const double PI=acos(-1.0);
//const ll INF=(1LL<<60);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; int ans[][];
ll m[]={,,,,,,,,,,}; int geet(int n,int b)
{
int sum=;
while(n>)
{
sum+=n%b;
n/=b;
}
return sum;
} ll get(ll n,ll b)
{
ll temp=n;
int l=;
while(temp>)
{
temp/=b;
l++;
}
ll sum=;
ll val[];
val[l]=;
n++;
for(int i=l-;i>=;--i)
val[i]=val[i+]*b;
for(int i=;i<=l;++i)
{
ll LOOP=n/(val[i]*b);
sum+=LOOP*m[b]*val[i];
ll len=n%(val[i]*b);
int start=;
while(len>=val[i])
{
sum+=start*val[i];
start++;
len-=val[i];
}
sum+=len*start;
}
return sum;
} int main()
{
int T,cont=;
sc("%d",&T);
while(T--)
{
ll n;int b;
sc("%lld%d",&n,&b);
for(int i=;i<=;++i)
{
ans[i][]=;
for(int j=;j<=;++j)
ans[i][j]=ans[i][j-]*b;
}
// for(int i=1;i<=100;++i)
// pr("%lld\n",get(i,2));
pr("Case #%d: %lld\n",++cont,get(n,b));
}
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

最新文章

  1. 【原】Go语言及Web框架Beego环境无脑搭建
  2. MyBlog
  3. 微信公众号支付之坑:调用支付jsapi缺少参数 timeStamp等错误解决方法
  4. C#中ref,out
  5. iOS-Xcode上传后iTunes Connect构建版本不显示
  6. 【读书笔记】iOS-Xcode知识-多线程
  7. js中的等号与非等号
  8. 深入理解计算机系统第二版习题解答CSAPP 2.18
  9. 中国剩余定理模板poj1006
  10. poj3159 Candies(差分约束)
  11. 线程间使用socket通信的计算器
  12. OpenGL学习-------绘制简单的几何图形
  13. Abp(.NetCore)开发与发布过程
  14. 对Javascript到底了解多少,一测便知道
  15. Shodan的http.favicon.hash语法详解与使用技巧
  16. iOS 使用GRMustache对HTML页面进行渲染
  17. jenkins 关闭和重启的实现
  18. html5 video标签屏蔽右键视频另存为的js代码-HTML5教程
  19. tomcat通过一个端口号实现多域名访问
  20. Java对象之间的深度复制拷贝

热门文章

  1. Leetcode题目215.数组中的第K个最大元素(中等)
  2. Leetcode题目79.单词搜索(回溯+DFS-中等)
  3. Leetcode题目56.合并区间(中等)
  4. OUC_Summer Training_ DIV2_#16 725
  5. cucumber+testng
  6. 服务器开启FTP功能
  7. LC 641. Design Circular Deque
  8. Win10+VS2017配置pthread
  9. sparkstreaming的状态计算-updateStateByKey源码
  10. R语言与概率统计(三) 多元统计分析(中)