LightOJ-1028 Trailing Zeroes (I)---因子数目
题目链接:
https://cn.vjudge.net/problem/LightOJ-1028
题目大意:
一个十进制数1≤n≤1012,现在用base进制来表示,问有多少种表示方法使得最后一位上的数为0?
等同于求出n有多少种约数,即n%base==0;
解题思路:
模板大法
注意:base进制不可能为1,算出的结果应该减去因子1
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 #include<queue> 7 #include<stack> 8 #include<map> 9 #include<sstream> 10 #define Mem(a, b) memset(a, b, sizeof(a)) 11 using namespace std; 12 typedef long long ll; 13 const int INF = 1e9 + 7; 14 const int maxn = 1000000+10; 15 int prime[maxn]; 16 bool is_prime[maxn]; 17 int sieve(int n)//返回n以内素数的个数 18 { 19 int p = 0; 20 for(int i = 0; i <= n; i++)is_prime[i] = 1; 21 is_prime[0] = is_prime[1] = 0; 22 for(ll i = 2; i <= n; i++) 23 { 24 if(is_prime[i]) 25 { 26 prime[p++] = i; 27 for(ll j = i * i; j <= n; j += i)is_prime[j] = 0;//这里涉及i*i,必须使用long long 28 } 29 } 30 return p; 31 } 32 33 ll Divisors_num(ll n, int tot)//素数总数 34 { 35 ll ans = 1; 36 for(int i = 0; i < tot && prime[i] * prime[i] <= n; i++) 37 { 38 if(n % prime[i] == 0) 39 { 40 int cnt = 0; 41 while(n % prime[i] == 0) 42 { 43 cnt++; 44 n /= prime[i]; 45 } 46 ans *= (cnt + 1); 47 } 48 } 49 if(n > 1)ans *= 2; 50 return ans; 51 } 52 int main() 53 { 54 int T, cases = 0; 55 int tot = sieve(1000000); 56 cin >> T; 57 while(T--) 58 { 59 ll n; 60 cin >> n; 61 cout<<"Case "<<++cases<<": "<<Divisors_num(n, tot)-1<<endl; 62 } 63 return 0; 64 }
转载于:https://www.cnblogs.com/fzl194/p/9017510.html
LightOJ-1028 Trailing Zeroes (I)---因子数目相关推荐
- [LeetCode] Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- Leet Code OJ 172. Factorial Trailing Zeroes [Difficulty: Easy]
题目: Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in ...
- Leetcode 172 Factorial Trailing Zeroes
1.题目要求 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be ...
- C#LeetCode刷题之#172-阶乘后的零(Factorial Trailing Zeroes)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3854 访问. 给定一个整数 n,返回 n! 结果尾数中零的数量. ...
- leetcode python3 简单题172. Factorial Trailing Zeroes
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百七十二题 (1)题目 英文: Given an integer n, retu ...
- 172 Factorial Trailing Zeroes(阶乘后的零)————附带详细思路和代码
文章目录 0 效果 1 题目 2 思路 3 代码 0 效果 1 题目 Given an integer n, return the number of trailing zeroes in n!. N ...
- 172. Factorial Trailing Zeroes
/**172. Factorial Trailing Zeroes *2016-6-4 by Mingyang* 首先别忘了什么是factorial,就是阶乘.那么很容易想到需要统计* (2,5)对的 ...
- [LintCode] Trailing Zeroes 末尾零的个数
Write an algorithm which computes the number of trailing zeros in n factorial. Have you met this que ...
最新文章
- mysql修改最后一条记录删除第一条记录
- LNK1146: 没有用选项“/LIBPATH:”指定的参数
- (39)通过 PID 获取 EPROCESS
- python 轨迹预测_CVPR 2019轨迹预测竞赛冠军方法总结
- Snabbdom(虚拟dom-6-createElm函数)
- 【评论分享有礼】毕业遇上疫情怎么办?4条技术指南轻松应对(内含求职、租房攻略)
- 基于Struts2框架的超市人事工资管理系统
- 测试驱动开发与极限编程思想浅析
- 计算机基础综合知识试题及答案,计算机基础综合知识试题及答案
- 蓝牙模块HC-06的基本设置和他的AT指令集
- 软件测试之App测试-用户体验测试
- 实用小技巧 利用Python一秒将全部中文名转为拼音
- 商业智能BI的特点及发展
- vs2019报错 声明与xxxx不兼容
- 重装系统感悟之设置系统还原点
- 几行代码教你爬取LOL皮肤图片
- 大数据相关资料论文小结
- mysql 命令行操作
- Hybird App混合移动应用开发技术整体解决方案,速来围观!
- 【KMP】Radio Transmission(最小循环子串)
热门文章
- 怎么检查python是否安装成功-如何在Docker中检查是否安装了python包?
- python不想学了-十分钟也学不会python?就不要学python了
- python中文读音ndarray-numpy中的ndarray方法和属性详解
- pythonweb开发-Python Web开发从入门到精通
- linux第三方模块参数,Swift on Linux – 导入第三方模块
- spring中事件发布设计与实现
- 2017年最受欢迎的10个编程挑战网站
- 夏俊:深入网站服务端技术(一)——网站并发的问题
- 网络编程学习笔记(ioctl操作)
- 题目1148:Financial Management