Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your job is to determine S modulo 29 (the rest of the division of S by 29).

Take X = 1 for an example. The positive integer divisors of 2004^1 are 1, 2, 3, 4, 6, 12, 167, 334, 501, 668, 1002 and 2004. Therefore S = 4704 and S modulo 29 is equal to 6.

InputThe input consists of several test cases. Each test case contains a line with the integer X (1 <= X <= 10000000).

A test case of X = 0 indicates the end of input, and should not be processed. 
OutputFor each test case, in a separate line, please output the result of S modulo 29.

Sample Input

1
10000
0

Sample Output

6
10

同余定理:a*b%c=((a%c)*(b%c))%c 或者可以=a%c*b%c
    (a-b)%c=a%c-b%c,但是需要注意的是,如果计算出来为负数,需要加上出来c*1
 #include<stdio.h>
typedef long long ll; const int mod=;
int ksm(int x,int n)
{
int res=;
while(n>)
{
if(n&)
res=res*x%mod;
x=x*x%mod;
n>>=;
}
return res;
} int main()
{
int x;
int k2=ksm(,);
int k166=ksm(,); while(~scanf("%d",&x)&&x)
{
int k3=ksm(,x+);
if(k3-<)
k3=k3-+;
else
k3--; int k167=ksm(,x+);
if(k167-<)
k167=k167-+;
else
k167--; int s2=ksm(,*x+);
if(s2-<)
s2=s2-+;
else
s2--; int s3=k2*k3%;
int s167=k167*k166%;
int sum=s2*s3*s167;
printf("%d\n",sum%);
}
return ;
}

Hdu-1452-Happy 2004-费马小定理推除法逆元+同余定理+积性函数的更多相关文章

  1. hdu 4704 sum(费马小定理+快速幂)

    题意: 这题意看了很久.. s(k)表示的是把n分成k个正整数的和,有多少种分法. 例如: n=4时, s(1)=1     4 s(2)=3     1,3      3,1       2,2 s ...

  2. 题解报告:hdu 6440 Dream(费马小定理+构造)

    解题思路:给定素数p,定义p内封闭的加法和乘法运算(运算封闭的定义:若从某个非空数集中任选两个元素(同一元素可重复选出),选出的这两个元素通过某种(或几种)运算后的得数仍是该数集中的元素,那么,就说该 ...

  3. HDU 4704 Sum( 费马小定理 + 快速幂 )

    链接:传送门 题意:求 N 的拆分数 思路: 吐嘈:求一个数 N 的拆分方案数,但是这个拆分方案十分 cd ,例如:4 = 4 , 4 = 1 + 3 , 4 = 3 + 1 , 4 = 2 + 2 ...

  4. hdu 4704 Sum 【费马小定理】

    题目 题意:将N拆分成1-n个数,问有多少种组成方法. 例如:N=4,将N拆分成1个数,结果就是4:将N拆分成2个数,结果就是3(即:1+3,2+2,3+1)--1+3和3+1这个算两个,则这个就是组 ...

  5. HDU 1452 Happy 2004(因数和+费马小定理+积性函数)

    Happy 2004 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  6. 数论初步(费马小定理) - Happy 2004

    Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...

  7. 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum

    Sum Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...

  8. HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description   Sample Input 2 Sample Outp ...

  9. hdu 4704(费马小定理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4704 思路:一道整数划分题目,不难推出公式:2^(n-1),根据费马小定理:(2,MOD)互质,则2^ ...

随机推荐

  1. Centos6.5 安装 LAMP

    Centos 安装 LAMP 系统: Centos 6.5 Apache 2.4 + PHP 7.2 + Mysql 5.7 准备工作 centos 查看版本 查看 centos版本 How to C ...

  2. Q:简单实现URL只能页面跳转,禁止直接访问

    sessionStorage 用于临时保存同一窗口(或标签页)的数据,在关闭窗口或标签页之后将会删除这些数据,且不同标签页的session不能共享,通过此特性来控制某个页面只能通过上级页面同标签页跳转 ...

  3. leetcode-126-单词接龙

    题目描述: class Solution: def findLadders(self, beginWord: str, endWord: str, wordList: list) -> list ...

  4. 【JZOJ6403】a

    description analysis 考虑\((0,0,0)\)走到某个点\((i,j,k)\)的贡献,相当于插板问题 \(i+j\)个空插\(k\)个板可以有空,\(i\)个空插\(j\)个板可 ...

  5. struts-config.xml

    <struts-config>是struts的根元素,它主要有8个子元素,DTD定义如下: <!ELEMENT struts-config (data-sources?,form-b ...

  6. Python 爬取12306火车票

    获取火车站 stations.py #import certifi #import urllib3 import re import requests from pprint import pprin ...

  7. java web 在tomcat没有正常输出

    目录 文章背景 目录 问题介绍 问题解决 说明 参考文章 版本记录 文章背景 调试程序时候突然发现一些位置设置的日志输出没有了,最后总算是解决了! 目录 问题介绍 本地运行时候的环境如下: windo ...

  8. NX二次开发-NXOpen窗口打印NXMessageBox&ListingWindow

    NX9+VS2012 #include <NXOpen/NXObject.hxx> #include <NXOpen/Part.hxx> #include <NXOpen ...

  9. faster-rcnn算法总结

    faster-rcnn的整体流程比较复杂,尤其是数据的预处理部分,流程比较繁琐.我写faster-rcnn系列文章的目的是对该算法的原始版本有个整体的把握,如果需要使用该算法做一些具体的任务,推荐使用 ...

  10. random,time,sys,os,序列化模块

    random模块(随机数模块) 取随机小数: random.random() 取0-1之间的小数 random.uniform(x, y) 取x-y之间的小数 取随机整数: random.randin ...