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/
題目:
思路:
我們知道一個數在某一個進制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
總結
以上是生活随笔為你收集整理的EOJ Monthly 2019.2 (based on February Selection) D.进制转换的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 拨开云雾见月明
- 下一篇: [UE4]瞬移前后屏幕亮度变化,Get