zoukankan      html  css  js  c++  java
  • poj 1845 Sumdiv

    题目链接:http://poj.org/problem?id=1845

    题目大意:就是求A^B的因子和。。。。。

    思路:

    1、对随意的n。能够这么表示 n=p1^e1*p2^e2*p3*e3*......pn^en 。(p1,p2,p3......pn都为素数)    

     2、对随意的n的因子和为:(1+e1+e1^2+......+e1^p1)*(1+e2+e2^2+......+e2^p2)*......*(1+en+en^2+......en^p2)

    这儿关键是怎样求等比数列的和。。。。

    直接看代码吧。

    。。。

    code:

    #include<cstdio>
    #include<iostream>
    
    using namespace std;
    
    typedef __int64 LL;
    
    const int size=10000;
    const int mod=9901;
    
    LL sum(LL p,LL n);
    LL power(LL p,LL n);
    
    int main()
    {
        int A,B;
        int p[size];
        int n[size];
        while(scanf("%d%d",&A,&B)==2)
        {
            int i,k=0;
            for(i=2;i*i<=A;)
            {
                if(A%i==0)
                {
                    p[k]=i;
                    n[k]=0;
                    while((A%i)==1)
                    {
                        n[k]++;
                        A/=i;
                    }
                }
                if(i==2)
                {
                    i++;
                }
                else
                {
                    i+=2;
                }
            }
            if(A!=1)
            {
                p[k]=A;
                n[k++]=1;
            }
            int ans=1;
            for(i=0;i<k;i++)
            {
                ans=(ans*(sum(p[i],n[i]*B)%mod))%mod;
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
    
    LL sum(LL p,LL n)
    {
        if(n==0) return 1;
        if(n%2)
        {
            return (sum(p,n/2)*(1+power(p,n/2+1)))%mod;
        }
        else
        {
            return (sum(p,n/2-1)*(1+power(p,n/2+1))+power(p,n/2))%mod;
        }
    }
    
    LL power(LL p,LL n)
    {
        LL sq=1;
        while(n>0)
        {
            if(n%2) sq=(sq*p)%mod;
            n/=2;
            p=p*p%mod;
        }
        return sq;
    }
    


  • 相关阅读:
    activity
    笔记
    创建敌人基类
    让精灵改变方向并前进
    给敌人精灵创建帧动画
    每帧创建一个item
    lua -- 所有UI组件的基类
    lua -- 系统提示框
    lua -- 生成协议
    ES6,数组遍历
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/7360348.html
Copyright © 2011-2022 走看看