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)。

代码实现如下:

 1 #include <set>
 2 #include <map>
 3 #include <deque>
 4 #include <queue>
 5 #include <stack>
 6 #include <cmath>
 7 #include <ctime>
 8 #include <bitset>
 9 #include <cstdio>
10 #include <string>
11 #include <vector>
12 #include <cstdlib>
13 #include <cstring>
14 #include <iostream>
15 #include <algorithm>
16 using namespace std;
17
18 typedef long long LL;
19 typedef pair<LL, LL> pLL;
20 typedef pair<LL, int> pLi;
21 typedef pair<int, LL> pil;;
22 typedef pair<int, int> pii;
23 typedef unsigned long long uLL;
24
25 #define lson rt<<1
26 #define rson rt<<1|1
27 #define lowbit(x) x&(-x)
28 #define name2str(name) (#name)
29 #define bug printf("*********\n")
30 #define debug(x) cout<<#x"=["<<x<<"]" <<endl
31 #define FIN freopen("D://code//in.txt","r",stdin)
32 #define IO ios::sync_with_stdio(false),cin.tie(0)
33
34 const double eps = 1e-8;
35 const int mod = 1000000007;
36 const int maxn = 2e5 + 7;
37 const double pi = acos(-1);
38 const int inf = 0x3f3f3f3f;
39 const LL INF = 0x3f3f3f3f3f3f3f3fLL;
40
41 int t;
42 LL l, r, k, m;
43
44 int main(){
45     scanf("%d", &t);
46     while(t--) {
47         scanf("%lld%lld%lld%lld", &l, &r, &k, &m);
48         int flag = 1;
49         LL ans = 0, tmp = 1;
50         for(int i = 1; i <= m; i++) {
51             if(r / tmp < k) {
52                 flag = 0;
53                 break;
54             }
55             tmp = tmp * k;
56         }
57         if(!flag) {
58             printf("0\n");
59             continue;
60         }
61         ans = r / tmp - (l - 1) / tmp;
62         if(r / tmp >= k) {
63             tmp = tmp * k;
64             ans -= r / tmp - (l - 1) / tmp;
65         }
66         printf("%lld\n", ans);
67     }
68     return 0;
69 }

原文地址:https://www.cnblogs.com/Dillonh/p/10430190.html

时间: 2024-07-30 02:55:04

EOJ Monthly 2019.2 (based on February Selection) D.进制转换的相关文章

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(n,k)\)为满足要求的\(k\)元组个数,现在要求出\(\sum_{i=1}^n f(i,k),1\leq n\leq 10^9,1\leq k\leq 1000\). 思路: 首先来化简一下式子,题目要求的就是: \[ \begin{aligned} &\sum_{i=1}^n\sum_{j=1

EOJ Monthly 2019.2

题解 A 回收卫星 #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using namespace std; #define y1 y11 #define fi first #define se second #define pi acos(-1.0) #define LL long long //#define mp make_pair #defin

EOJ Monthly 2019.2 E 中位数 (二分+中位数+dag上dp)

题意: 一张由 n 个点,m 条边构成的有向无环图.每个点有点权 Ai.QQ 小方想知道所有起点为 1 ,终点为 n 的路径中最大的中位数是多少. 一条路径的中位数指的是:一条路径有 n 个点,将这 n 个点的权值从小到大排序后,排在位置 ⌊n2⌋+1 上的权值. 思路(官方题解): 考虑二分答案,我们需要验证路径最大的中位数是否 ≥mid . 我们把所有的点权做 −1/1 变换,即 ≥mid 的点权变为 1 ,否则变为 −1 . 根据题面路径中位数的定义,我们可以发现,如果这条路径的中位数 ≥

EOJ Monthly 2019.2 E. 中位数 (二分+dfs)

题目传送门 题意: 在一个n个点,m条边的有向无环图中,求出所有从1到n 的路径的中位数的最大值 一条路径的中位数指的是:一条路径有 n 个点, 将这 n 个点的权值从小到大排序后,排在位置 ⌊n2⌋+1 上的权值. 思路: 看到权值为1~1e9,可以想到用二分答案,然后我们在验证的时候 可以将小于mid的边权设为-1,大于为1这样遍历一遍序列加起来的值 刚好为0 代码: #include<bits/stdc++.h> using namespace std; typedef long lon

EOJ Monthly 2019.3A

A. 钝角三角形 单点时限: 3.0 sec 内存限制: 512 MB QQ 小方以前不会判断钝角三角形,现在他会了,所以他急切的想教会你. 如果三角形的三边长分别为 a, b, c (a≤b≤c),那么当满足 a2+b2<c2 且 a+b>c 的时候,这个三角形就是一个由三边长为 a, b, c 构成的钝角三角形. 单单讲给你听肯定是不够的,为了表现自己,QQ 小方现在要考考你. 现在 QQ 小方会给你一个包含 3n 个整数的集合,分别是 {2,3,4,?3n,3n+1} ,他想让你将这个集

[EOJ Monthly] 2019.9

https://acm.ecnu.edu.cn/contest/196/ 这次是ECNU的校内选拔应该会简单一点? 下午嘉定有彩虹,在村(学)子(校)里面转了一圈,学校真大,没什么人,火烧云真美,台风 要 来 了 打开比赛,看看D:要求概率 不会是签到 看看C:这么大的模拟,不是签到 看看A:要么找规律要么SG,然后很长时间都没有人过,可能是SG,算了不管了 后来队里面有人说D是知乎原题 拿到公式开始交 逆元用费马大定理求 敲敲敲... WA WOC??为什么WA,请教了大佬队友,费马大定理会爆

EOJ Monthly 2019.11 B字母游戏

题目见:https://acm.ecnu.edu.cn/contest/231/problem/B/ 卡在第二个点和第十二个点上无数次. 和226打电话,226建议双哈希,然后一发过了....(这是226大佬的力量啊) #include<cstdio> #include<cstring> #include<algorithm> #define maxn 1005 const int mod[2]={19260817,19190504},mul[2]={29,11}; i

EOJ Monthly 2018.1 F 最小OR路径

题目链接 Description 给定一个有 \(n\) 个点和 \(m\) 条边的无向图,其中每一条边 \(e_i\) 都有一个权值记为 \(w_i\) . 对于给出的两个点 \(a\) 和 \(b\) ,求一条 \(a\) 到 \(b\) 的路径,使得路径上的边权的 \(OR\)(位或)和最小,输出这个值.(也就是说,如果将路径看做边的集合 \(\{e_1,e_2,-,e_k\}\),那么这条路径的代价为 \(w_1\ OR\ w_2\ OR\ -\ OR\ w_k\),现在求一条路径使得其

【EOJ Monthly 2018.2 (Good bye 2017)】

23333333333333333 由于情人节要回家,所以就先只放代码了. 此题是与我胖虎过不去. [E. 出老千的 xjj] #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int maxn=3000000; #define ll long long int