Codeforces 1114C(数论)】的更多相关文章

大意: 求n!在b进制下末尾0的个数 等价于求n!中有多少因子b, 素数分解一下, 再对求出所有素数的最小因子数就好了 ll n, b; vector<pli> A, res; void factor(ll x) { int mx = sqrt(x+0.5); REP(i,2,mx) if (x%i==0) { int t = 0; while (x%i==0) x/=i,++t; A.pb(pli(i,t)); } if (x>1) A.pb(pli(x,1)); } int main…
题面 传送门 分析 我们先考虑n!在10进制下有多少个0 由于10=2*5, 我们考虑n!的分解式中5的指数,答案显然等于\(\frac{n}{5}+\frac{n}{5^2}+\frac{n}{5^3}+\dots\frac{n}{5^k}(\frac{n}{5^k}\geq 1,\frac{n}{5^{k+1}}<1)\) 可以用一个递归函数来计算: ll f(ll x,ll y){ if(x<y) return 0; else return x/y+f(x/y,y); } 由于5的个数显…
https://codeforces.com/contest/1114/problem/C 很有趣的一道数论,很明显是要求能组成多少个基数. 可以分解质因数,然后统计各个质因数的个数. 比如8以内,有8/2=4个2+8/4=2个2+8/8=1个2,这样统计是log复杂的. 需要小心的是乘法爆ll的情况,实际上改成从最高的开始往下除可以避免. 然后求这些质因数分解是b的质因数分解的几倍. 然后还有一个bug就是,当n!中缺少b的某个或全部因子时,问题很大. #include<bits/stdc++…
A - A Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 300C Description Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the deci…
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序列中所有值都能被其中一个值整除,②且子序列范围尽可能大(r-l尽可能大). 解题思路: 对于要求1,不难发现只有min(L,R)=gcd(L,R)时才行.其中gcd是L,R范围内的最大公约数,min是L,R范围内的最小值. 对于要求2,传统思路是r-l从大到小枚举,每次确定一个(L,R)范围,进行判…
题目链接:http://codeforces.com/problemset/problem/264/B 代码: #include<cstdio> #include<iostream> #include<vector> #include<cstring> using namespace std; ; int dp[maxn]; vector<int> dx[maxn]; void get_div() //筛因子 { ; i<maxn; i++…
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum_{i = 1}^{n} a_{i} \leqslant K$的最大正整数$d$. 整理一下可以得到条件是$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil \leqslant K + \sum_{i = 1}^{n} a_{i}$…
题目连接 : https://codeforces.com/contest/1114/problem/C 题目大意:给一个整数n(1e18>=n>=0),和一个整数k(1e12>=k>=2),问n!在k进制情况下末尾有多少个0. 题目很好理解,思路也很有意思,首先n!在十进制下有多少个0,很好想,10分解质因数有2,5,无论在什么情况下n!中分解出5的个数比2多, 分解是这个意思,5能找出1个5,10能找出一个5,25能找出2个5(因为是5*5,可以被5除两次).以此类推,找这个东…
题目 CodeForces 1213G 做法 假设有\(P\)个完整的循环块,假设此时答案为\(K\)(实际答案可能有多种),即每块完整块长度为\(K\),则\(P=\left \lfloor \frac{N}{K} \right \rfloor\) 假设循环快中有\(p_a,p_b\)个\(A\)和\(B\),则 \(p_a\cdot P\le a\Longrightarrow p_a\le \left \lfloor \frac{a}{P} \right \rfloor\) \(p_a\cd…
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom…