EOJ Monthly 2019.2 (based on February Selection) D.进制转换
题目链接:
https://acm.ecnu.edu.cn/contest/140/problem/D/
题目:

思路:
我们知道一个数在某一个进制k下末尾零的个数x就是这个数整除kx,这题要求刚好末尾有m个0,还需要除去高位为0的情况,因此这题答案就是r / kx-(l-1)/kx-(r/kx+1-(l-1)/kx+1)。
代码实现如下:
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-;
const int mod = ;
const int maxn = 2e5 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int t;
LL l, r, k, m; int main(){
scanf("%d", &t);
while(t--) {
scanf("%lld%lld%lld%lld", &l, &r, &k, &m);
int flag = ;
LL ans = , tmp = ;
for(int i = ; i <= m; i++) {
if(r / tmp < k) {
flag = ;
break;
}
tmp = tmp * k;
}
if(!flag) {
printf("0\n");
continue;
}
ans = r / tmp - (l - ) / tmp;
if(r / tmp >= k) {
tmp = tmp * k;
ans -= r / tmp - (l - ) / tmp;
}
printf("%lld\n", ans);
}
return ;
}
EOJ Monthly 2019.2 (based on February Selection) D.进制转换的更多相关文章
- EOJ Monthly 2019.2 (based on February Selection) D 进制转换 【数学 进制转换】
任意门:https://acm.ecnu.edu.cn/contest/140/problem/D/ D. 进制转换 单测试点时限: 2.0 秒 内存限制: 256 MB “他觉得一个人奋斗更轻松自在 ...
- EOJ Monthly 2019.2 (based on February Selection) F.方差
题目链接: https://acm.ecnu.edu.cn/contest/140/problem/F/ 题目: 思路: 因为方差是用来评估数据的离散程度的,因此最优的m个数一定是排序后连续的,所以我 ...
- EOJ Monthly 2019.2 题解(B、D、F)
EOJ Monthly 2019.2 题解(B.D.F) 官方题解:https://acm.ecnu.edu.cn/blog/entry/320/ B. 解题 单测试点时限: 2.0 秒 内存限制: ...
- EOJ Monthly 2019.11 E. 数学题(莫比乌斯反演+杜教筛+拉格朗日插值)
传送门 题意: 统计\(k\)元组个数\((a_1,a_2,\cdots,a_n),1\leq a_i\leq n\)使得\(gcd(a_1,a_2,\cdots,a_k,n)=1\). 定义\(f( ...
- EOJ Monthly 2019.2
题解 A 回收卫星 #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/s ...
- EOJ Monthly 2019.1 唐纳德先生与这真的是签到题吗 【数学+暴力+multiset】
传送门:https://acm.ecnu.edu.cn/contest/126/ C. 唐纳德先生与这真的是签到题吗 单测试点时限: 6.0 秒 内存限制: 1024 MB 唐纳德先生在出月赛的过程中 ...
- EOJ Monthly 2019.3 A
A. 钝角三角形 单点时限: 3.0 sec 内存限制: 512 MB QQ 小方以前不会判断钝角三角形,现在他会了,所以他急切的想教会你. 如果三角形的三边长分别为 a, b, c (a≤b≤c), ...
- eoj monthly 2019.11
原题 T1 纸条 题目大意: 给出一个长度为n的字符串,其中m位未知,对于每一位未知的字母,有k个备选字母,最终答案为备选字母按字典序排序后的第x个. 题解: 签到题-- 按照题目意思直接写就可以了. ...
- EOJ Monthly 2019.2 E. 中位数 (二分+dfs)
题目传送门 题意: 在一个n个点,m条边的有向无环图中,求出所有从1到n 的路径的中位数的最大值 一条路径的中位数指的是:一条路径有 n 个点, 将这 n 个点的权值从小到大排序后,排在位置 ⌊n2⌋ ...
随机推荐
- 在Android上使用Socket
原文地址:http://www.cnblogs.com/kross/p/3621952.html 考虑到以后可能要用到这方面的知识,就来写个Demo尝试下,其实以前学过,但不记得了……(用不到的东西各 ...
- java 常见的异常大集合
算术异常类:ArithmeticExecption 空指针异常类:NullPointerException 类型强制转换异常:ClassCastException 数组负下标异常:NegativeAr ...
- 用JavaScript添加选择按钮的背景颜色和juqery添加选择按钮的背景色
在项目开发中经常遇到要选择的按钮,选择完之后被选择的按钮的背景色会发生变化,表示被选择 样式图如下: 每点击一个数字,相应的背景色变为蓝色,其他的依旧是白色,先用JavaScript实现 html代码 ...
- Nginx - request_time和upstream_response_time的区别
request_time 官网描述:request processing time in seconds with a milliseconds resolution; time elapsed be ...
- BZOJ1064 NOI2008假面舞会(dfs树)
将图中的环的长度定义为正向边数量-反向边数量,那么答案一定是所有环的环长的共同因子.dfs一下就能找到图中的一些环,并且图中的所有环的环长都可以由这些环长加加减减得到(好像不太会证).如果有环长为1或 ...
- 加密,解密web.config数据库连接字符串
"connectionStrings" 路径是web.config所在的工程目录. 1.加密EncryptWebConfig.bat @echo offC:\Windows\Mic ...
- 百度地图经纬度批量查找功能XGeocoding使用手册
<XGeocoding使用手册> 1.下载XGeocoding V2 http://www.gpsspg.com/xgeocoding/download/ 2.解压XGeocoding_v ...
- java多线程 -- 同步鎖
为了解决多线程安全问题在 Java 5.0 之前,协调共享对象的访问时可以使用的机制只有 synchronized 和 volatile .Java 5.0 后增加了一些新的机制,但并不是一种替代内置 ...
- idea中Hibernate错误:无法解析表
idea中Hibernate错误:无法解析表 这种情况主要是在idea中使用hibernate自定义注解,idea无法检查数据源 this inspecton controls whether the ...
- 【费用流】【网络流24题】【P1251】 餐巾计划问题
Description 一个餐厅在相继的 \(N\) 天里,每天需用的餐巾数不尽相同.假设第 \(i\) 天需要 \(r_i\)块餐巾.餐厅可以购买新的餐巾,每块餐巾的费用为 \(p\) 分;或者把旧 ...