D - Div Game -- ATCODER
-- div Game Atcoder
2023-09-27 14:28:34 时间
D - Div Game
https://atcoder.jp/contests/abc169/tasks/abc169_d
参考: https://blog.csdn.net/justidle/article/details/106474626
思路
计算n中所有质数的幂,
Note: 此处不需要使用筛法先求出所有的质数,然后计算其幂
i在[2, sqrt(n)]范围, 但是在质数判定完成后, 可以使用 n/=质数, 来动态减少[2, sqrt(n)]范围
此外质数的出现个数,使用map<ll, ll> counter数据结构来存储,
每个质数判定后,counter++;
对于幂,使用1,2,3,...x = (1+x)*x/2来计算最大的x,即x个满足要求的因子
Code
https://atcoder.jp/contests/abc169/submissions/35981643
long long n; map<long long, long long> counter; int main() { cin >> n; for(long long i=2; i*i<=n; i++){ while(n % i == 0){ counter[i]++; n /= i; } } if (n > 1){ counter[n]++; } long long sum = 0; map<long long, long long>::iterator it; for(it=counter.begin(); it!=counter.end(); it++){ long long total = it->second; long long i; for(i=1; i*(i+1)/2<=total; i++); i--; sum += i; } cout << sum << endl; return 0; }
相关文章
- 条件注释判断浏览器<!--[if !IE]><!--[if IE]><!--[if lt IE 6]><!--[if gte IE 6]>
- 8 -- 深入使用Spring -- 5...1 启用Spring缓存
- English trip -- VC(情景课)5 D
- Spark源码分析 -- SchedulableBuilder
- 统计学习方法笔记 -- Boosting方法
- Lua 之 for 循环 -- 循环条件不会改变循环次数
- java.sql.SQLException: Lock wait timeout exceeded --转
- 详解 Spring 3.0 基于 Annotation 的依赖注入实现--转载
- 如何使用JCA (J2EE 连接器架构)实现企业应用--转载
- Programmer Competency Matrix--ref--http://sijinjoseph.com/programmer-competency-matrix/
- ESP32系列--ESP32各个系列对比
- CCNA--GNS3仿真环境的搭建及SecureCRT8.7程序控制台美化调试