Light OJ 1028 Trailing Zeroes (I) 求n因子数

2024-06-15 11:48

本文主要是介绍Light OJ 1028 Trailing Zeroes (I) 求n因子数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目来源:Light OJ 1028

题意:求一个数转化成任意进制后末尾有0的种数 就是一个数因子的个数

思路:一个数可以被分解成若干素数相乘 p1^x1*p2^x2*...*pn^xn

根据乘法原理 因子数为 (x1+1)*(x2+1)*...*(xn+1)

注意剪枝

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
//筛素数 
const int maxn = 1000010;
bool vis[maxn];
int prime[maxn];int sieve(int n)
{memset(vis, 0, sizeof(vis));vis[0] = vis[1] = 1;int c = 0;for(int i = 2; i <= n; i++)if(!vis[i]){prime[c++] = i;for(int j = 2*i; j <= n; j += i)vis[j] = 1;}return c;
}int main()
{int c = sieve(1000000);int cas = 1;int T;scanf("%d", &T);while(T--){long long n, ans = 1;scanf("%lld", &n);for(int i = 0; i < c && prime[i]*prime[i] <= n; i++){if(prime[i] > n)break;if(n % prime[i] == 0){long long sum = 1;while(n % prime[i] == 0){sum++;n /= prime[i];}ans *= sum;}}if(n > 1)ans *= 2;printf("Case %d: %lld\n", cas++, ans-1);}return 0;
}


 

 

这篇关于Light OJ 1028 Trailing Zeroes (I) 求n因子数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1063368

相关文章

线性因子模型 - 独立分量分析(ICA)篇

序言 线性因子模型是数据分析与机器学习中的一类重要模型,它们通过引入潜变量( latent variables \text{latent variables} latent variables)来更好地表征数据。其中,独立分量分析( ICA \text{ICA} ICA)作为线性因子模型的一种,以其独特的视角和广泛的应用领域而备受关注。 ICA \text{ICA} ICA旨在将观察到的复杂信号

Web Navigation POJ 1028 栈操作

模拟平时上网打开网页的操作,值得注意的是,如果BACK回一个网页之后进行VISIT操作,之前的网页FORWARD都回不去了 #include<cstdio>#include<cstring>#include<iostream>#include<stack>using namespace std;#define MAXD 20#define MAX_SIZE 100 + 10co

HDU2521(求因子个数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2521 解题思路: 数据量不大,直接O(n)遍历,对每个数求其因子个数,找出最大的即可。 完整代码: #include <functional>#include <algorithm>#include <iostream>#include <fstream>#includ

哈理工OJ 2179(深搜)

组合 Time Limit: 1000 MSMemory Limit: 32768 K Total Submit: 7(5 users)Total Accepted: 6(5 users)Rating: Special Judge: No Description 给出一个正整数N,从集合{1,2,3..N} 中找出所有大小为k的子集, 并按照字典序从小到大输出。 Input 第一行是一个整

每日OJ_牛客_求和(递归深搜)

目录 牛客_求和(递归深搜) 解析代码 牛客_求和(递归深搜) 求和_好未来笔试题_牛客网 解析代码         递归中每次累加一个新的数,如果累加和大于等于目标,结束递归。此时如果累加和正好等于目标,则打印组合。向上回退搜索其它组合。此题本身就是一个搜索的过程,找到所有的组合。 #include <iostream>#include <cmath>#in

连分数因子分解法——C语言实现

参考网址:连分数分解法寻找整数的因子(Python)-CSDN博客 大数运算:C语言实现 大数运算 加减乘除模运算 超详细_64编程 加减乘除取模 复杂运算-CSDN博客 ‌连分数因子分解法‌是一种用于大整数因子分解的算法,它是计算数论中的一个重要方法。连分数因子分解法通过寻找x2≡y2 (mod p)x2≡y2 (mod p)的形式来分解N。具体来说,这种方法涉及到计算N的简单连分数展开,并

js算法题,给任意一个偶数,找出他的所有的质数因子

/*给任意一个偶数,找出他的所有的质数因子*/ function primeFactor(n){     var factors=[],            divistor=2;     if(typeof n !=='number'||!Number.isInteger(n)){          return 0;     }; //如果不是偶数返回0,如果是0,返回0

OJ-0905

题目 示例1: 输入:10 10 56 34 99 1 87 8 99 3 255 6 99 5 255 4 99 7 255 2 99 9 255 213 4输出:99 示例2: 输入:10 10 255 34 0 1 255 8 0 3 255 6 0 5 255 4 0 7 255 2 0 9 255 213 5输出:255 import java.util.

[LeetCode] 283. Move Zeroes

题:https://leetcode.com/problems/move-zeroes/submissions/1 题目 Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. Ex

[LeetCode] 474. Ones and Zeroes

题:https://leetcode.com/problems/ones-and-zeroes/description/ 题目 In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue. For now, suppos