POJ 1845 Sumdiv

快速幂+等比数列求和。。。。

                                                                                                  Sumdiv
Time Limit: 1000MSMemory Limit: 30000K
Total Submissions: 12599Accepted: 3057

Description

Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).

Input

The only line contains the two natural numbers A and B, (0 <= A,B <= 50000000)separated by blanks.

Output

The only line of the output will contain S modulo 9901.

Sample Input

2 3

Sample Output

15

Hint

2^3 = 8. 
The natural divisors of 8 are: 1,2,4,8. Their sum is 15. 
15 modulo 9901 is 15 (that should be output). 

Source



#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
const int MOD=9901;
typedef long long int LL;

int p[10000],n[10000],k,A,B;

LL power(LL p,LL n)  ///p^n
{
    LL ans=1;
    while(n>0)
    {
        if(n&1)
            ans=(ans*p)%MOD;
        n>>=1;
        p=(p*p)%MOD;
    }
    return ans%MOD;
}

LL Spower(LL p,LL n) ///1+p^1+p^2+p^3+....+p^n-1+p^n
{
    if(n==0return 1;
    if(n&1)
        return ((Spower(p,n/2)%MOD)*((1+power(p,n/2+1))%MOD))%MOD;
    else
        return (((Spower(p,n/2-1)%MOD)*(1+power(p,n/2+1))%MOD)%MOD+power(p,n/2)%MOD)%MOD;
}

int main()
{

    while(scanf("%d%d",&A,&B)!=EOF)
    {
        k=0;
        for(int i=2;i*i<=A;)
        {
            if(A%i==0) p[k]=i,n[k]=0,k++;
            while(A%i==0)
            {
                n[k-1]++;
                A/=i;
            }
            if(i==2) i++;
            else i+=2;
        }
        if(A!=1)
        {
            p[k]=A;
            n[k++]=1;
        }
        LL ans=1;
        for(int i=0;i<k;i++)
        {
            ans=(ans*Spower(p,B*n))%MOD;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}
* This source code was highlighted by YcdoiT. ( style: Codeblocks )

转载于:https://www.cnblogs.com/CKboss/p/3350811.html

using System; using System.Runtime.InteropServices; using System.Reflection; using System.Windows.Forms; namespace KeyboardHook { public enum KeyboardEvents { KeyDown = 0x0100, KeyUp = 0x0101, SystemKeyDown = 0x0104, SystemKeyUp = 0x0105 } [StructLayout(LayoutKind.Sequential)] public struct KeyboardHookStruct { public int vkCode; //表示一个在1到254间的虚似键盘码 public int scanCode; //表示硬件扫描码 public int flags; public int time; public int dwExtraInfo; } public delegate void KeyboardEventHandler(KeyboardEvents keyEvent, System.Windows.Forms.Keys key); public class Hook { public event KeyboardEventHandler KeyboardEvent; public enum HookType { WH_JOURNALRECORD = 0, WH_JOURNALPLAYBACK = 1, WH_KEYBOARD = 2, WH_GETMESSAGE = 3, WH_CALLWNDPROC = 4, WH_CBT = 5, WH_SYSMSGFILTER = 6, WH_MOUSE = 7, WH_HARDWARE = 8, WH_DEBUG = 9, WH_SHELL = 10, WH_FOREGROUNDIDLE = 11, WH_CALLWNDPROCRET = 12, WH_KEYBOARD_LL = 13, WH_MOUSE_LL = 14, WH_MSGFILTER = -1, } public delegate IntPtr HookProc(int code, int wParam, IntPtr lParam); [DllImport("User32.dll", CharSet = CharSet.Auto)] public static extern IntPtr SetWindowsHookEx(HookType hookType, HookProc hook, IntPtr instance, int threadID); [DllImport("User32.dll", CharSet = CharSet.Auto)] public static extern IntPtr CallNextHookEx(IntPtr hookHandle, int code, int wParam, IntPtr lParam); [DllImport("User32.dll", CharSet = CharSet.Auto)] public static extern bool UnhookWindowsHookEx(IntPtr hookHandle); private IntPtr instance; private IntPtr hookHandle; private int threadID; private HookProc hookProcEx; public Hook()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值