Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)
Total Submission(s): 662    Accepted Submission(s): 351

Problem Description

As we all know,a palindrome number is the number which reads the same backward as forward,such as 666 or 747.Some numbers are not the palindrome numbers in decimal form,but in other base,they may become the palindrome number.Like 288,it’s not a palindrome number under 10-base.But if we convert it to 17-base number,it’s GG,which becomes a palindrome number.So we define an interesting function f(n,k) as follow:
f(n,k)=k if n is a palindrome number under k-base.
Otherwise f(n,k)=1.
Now given you 4 integers L,R,l,r,you need to caluclate the mathematics expression ∑Ri=L∑rj=lf(i,j) .
When representing the k-base(k>10) number,we need to use A to represent 10,B to represent 11,C to repesent 12 and so on.The biggest number is Z(35),so we only discuss about the situation at most 36-base number.

Input

The first line consists of an integer T,which denotes the number of test cases.
In the following T lines,each line consists of 4 integers L,R,l,r.
(1≤T≤105,1≤L≤R≤109,2≤l≤r≤36)

Output

For each test case, output the answer in the form of “Case #i: ans” in a seperate line.

Sample Input

3
1 1 2 36
1 982180 10 10
496690841 524639270 5 20

Sample Output

Case #1: 665
Case #2: 1000000
Case #3: 447525746

Source

2017中国大学生程序设计竞赛 - 网络选拔赛

//题意:给出四个整数,L,R,l,r, ∑(L<=i<=R)∑(l<=j<=r) f(i,j) , f(i,j)代表 i 在 j 进制下是否为回文数,是为 k,否则值为 1。

//题解:枚举进制,那么就变为 cal(R,k) - cal(L-1,k) { cal(i,j)表1--i,在k进制下的回文数个数*k+其余数的个数 } 的累加了

计算小于等于一个数的回文数个数并不难,想清楚就好,如果某数前半部分小于该数的前半部分,那一定能构造出来,所以等于时特判一下即可

 # include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <sstream>
# include <set>
# include <cmath>
# include <algorithm>
# pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
# define LL long long
# define pr pair
# define mkp make_pair
# define lowbit(x) ((x)&(-x))
# define PI acos(-1.0)
# define INF 0x3f3f3f3f3f3f3f3f
# define eps 1e-
# define MOD inline int scan() {
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
inline void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
#define MX 500
/**************************/ LL cal(LL x,LL k)
{
int len=;
LL temp=x;
int dat[];
while (temp)
{
dat[len++]=temp%k;
temp/=k;
} LL ans = ,sum = k-,base=;
for (int i=;i<len;i++)
{
ans+=sum-base;
if (i%==)
{
base=sum;
sum=sum*k+k-;
}
}
LL sb=;
for (int i=len-;i>=len/;i--)
sb = sb*k+dat[i];
LL now=sb;
int wei;
if (len%) wei=len/+;
else wei = len/;
for (int i=wei;i<len;i++)
sb = sb*k+dat[i]; if (sb<=x)
ans+=now-base;
else
ans+=now-base-;
return ans*(k-)+x;
} int main()
{
int T = scan();
for (int cnt=;cnt<=T;cnt++)
{
int L,R,l,r;
scanf("%d%d%d%d",&L,&R,&l,&r);
LL ans = ;
for (int i=l;i<=r;i++)
{
ans +=cal(R,i)-cal(L-,i);
}
printf("Case #%d: %lld\n",cnt,ans);
}
return ;
}

最新文章

  1. 前端自动化构建工具gulp记录
  2. TortoiseSVN与VisualSVN Server搭建SVN版本控制系统
  3. 【读书笔记】iOS-使用应用内支付注意事项
  4. ansible高级用法
  5. java学习笔记 (8) —— Struts2 实现上传
  6. ROBOTS.TXT屏蔽笔记、代码、示例大全
  7. ASP.NET Identity 身份验证和基于角色的授权
  8. Router
  9. svn clean up 出错解决方案
  10. 理解Node.js的事件轮询
  11. Eclipse安装反编译工具JadClipse for Eclipse手把手教程
  12. Window下通过CuteFTP与Linux虚拟机连接失败的原因总结及解决方法
  13. 18 UI美化自定义形状shape
  14. shiro注解
  15. 迁移32位下的旧代码到64位sever遇到过的两个很诡异的问题
  16. MyBatis-DynamicSQL 动态SQL
  17. 024_nginx之backlog坑
  18. xxx.jar 中没有主清单属性
  19. 11款CSS3动画工具的开发
  20. Nginx之基本介绍(一)

热门文章

  1. Bat 获取本地代码的Svn Revision并保存到变量
  2. Server 非阻塞
  3. Unity Shader 效果学习
  4. Rational Performance Tester(RPTv8.6) 在launch Schedule 时一直卡在 29%
  5. JavaScript | 基础表单验证(纯Js)
  6. python基础 实战作业 ---Excel基本读写与数据处理
  7. 关于继承Fragment后重写构造方法而产生的错误
  8. MATLAB 的通用命令
  9. POJ训练计划3096_Surprising Strings(STL/map)
  10. 很实用的JQuery代码片段(转)