求因子个数和因子和

//求因子个数
int Facnt(int n)
{
    int res = 1;
    for(int i=2;i*i<=n;i++)
    {
        if(n%i == 0)
        {
            int cnt = 0;
            do
            {
                n /= i;
                cnt++;
            }while(n%i==0);
            res *= (cnt+1);
        }
    }
    if(n > 1)
        res = 2*res;
    return res;
}

//求因子和
int Facsum(int n)
{
    int res = 1;
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            int cnt = 1;
            do
            {
                n /= i;
                cnt *= i;
            }while(n%i==0);
            res = res*(cnt*i-1)/(i-1);
        }
    }
    if(n > 1)
        res *= (n+1);
    return res;
}

求因子个数和因子和,布布扣,bubuko.com

时间: 2024-12-17 09:44:33

求因子个数和因子和的相关文章

Almost All Divisors(求因子个数及思维)

---恢复内容开始--- We guessed some integer number xx. You are given a list of almost all its divisors. Almost all means that there are all divisors except 11and xx in the list. Your task is to find the minimum possible integer xx that can be the guessed nu

因子个数与因子和

题目:LightOJ:1341 - Aladdin and the Flying Carpet(因子个数) It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first mystery. Aladdin was about to enter to a m

Easy Number Challenge(暴力,求因子个数)

Easy Number Challenge Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 236B Appoint description:  System Crawler  (2016-04-26) Description Let's denote d(n) as the number of divisors of a

数学题 求因子个数

小C的倍数问题 Accepts: 1990 Submissions: 4931 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description 根据小学数学的知识,我们知道一个正整数x是3的倍数的条件是x每一位加起来的和是3的倍数.反之,如果一个数每一位加起来是3的倍数,则这个数肯定是3的倍数. 现在给定进制P,求有多少个B满足P进制下,一个正整数是B的倍数的

lightoj-1028 - Trailing Zeroes (I)(素数法求因子个数)

1028 - Trailing Zeroes (I) PDF (English) Statistics ForumTime Limit: 2 second(s) Memory Limit: 32 MBWe know what a base of a number is and what the properties are. For example, we use decimal number system, where the base is 10 and we use the symbols

POJ-2992 Divisors---组合数求因子数目

题目链接: https://cn.vjudge.net/problem/POJ-2992 题目大意: 给出组合数Cnk,求出其因子个数,其中n,k不大于431,组合数的值在long long范围内 解题思路: 由于只有431种阶乘,先预处理431中素数,再预处理出每一个阶乘里面所含的素因子的指数,然后对于组合数,直接用素因子指数相减即可. 求出的质因子指数,就可以用定理直接求因子个数. 1 #include<iostream> 2 #include<cstdio> 3 #inclu

Acdream1084 寒假安排 求n!中v因子个数

题目链接:点击打开链接 寒假安排 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Others) SubmitStatistic Next Problem Problem Description 寒假又快要到了,不过对于lzx来说,头疼的事又来了,因为众多的后宫都指望着能和lzx约会呢,lzx得安排好计划才行. 假设lzx的后宫团有n个人,寒假共有m天,而每天只能跟一位后宫MM约会,并且由于后宫

求一个数的因子个数

首先对要求的数进行质因数分解,然后求各因数的幂的积数,比如600 = 2^3 * 3^1 * 5^2 那么因子个数是(3+1)*(1+1)*(2+1) = 24 public class TestYuman{ public static void main(String[] args){ int res=get_factor(6); System.out.println(res); } public static int get_factor(int input) { int factor=1,

(hdu step 2.1.3)Largest prime factor(求一个数的最大质因子的位置)

题目: Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4868 Accepted Submission(s): 1452   Problem Description Everybody knows any number can be combined by the prime number.Now,