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. Maven pom配置(Spring+SpringMvc+mybaties)

    <?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven ...

  2. 使用babel转码器,让浏览器支持es6语法

    ECMAScript 6.0(以下简称 ES6)是 JavaScript 语言的下一代标准,可是很多浏览器并不支持es6语法,所以我们需要一个转码工具, 把es6的语法转换成浏览器支持的javascr ...

  3. Linux grep 后通过 | 在次grep

    grep 'info' info.log|grep 'info2' 先筛选出 包含‘info’的信息,再次筛选出包含'info2'的信息

  4. thinlphp配置加载

    在ThinkPHP中,一般来说应用的配置文件是自动加载的,加载的顺序是: 惯例配置->应用配置->模式配置->调试配置->状态配置->模块配置->扩展配置-> ...

  5. 帝国cms批量更新内容页

    系统设置->数据更新->批量更新信息页地址 系统设置->数据更新->数据整理: 再更新整站主要页面即可

  6. 好用的日期控件jeDate

    最近做公司后台系统关于仓库的一些东西,需要根据时间范围来导出一些数据,我们使用的后台框架是基于bs的,bs也有时间控件:bootstrap-datepicker是只能选择日期的, daterangep ...

  7. NX二次开发-UFUN获取当前导出CGM选项设置UF_CGM_ask_session_export_options

    文章转载自唐康林NX二次开发论坛,原文出处: http://www.nxopen.cn/thread-126-1-1.html 刚才有同学问到这个问题,如果是用NXOpen来做,直接录制一下就可以了: ...

  8. solr 查询同一个core 的关联字段

    实现一个core里面多个字段的关联查询: 应用场景是: 词, 句子,文章 希望通过查询实现词,句子,文章里面共同有的关键字 private static CloudSolrServer cloudSo ...

  9. 使用Pyppeteer进行gmail模拟登录

    import asyncio import time from pyppeteer import launch async def gmailLogin(username, password, url ...

  10. 精选15个国外CSS框架

    转自:http://blog.bingo929.com/css-frameworks-15.html 什么是css框架 实际上还是让我们从框架说起吧.框架就是一个你可以用于你的网站项目的基本的概念上的 ...