hdu 4704(费马小定理+快速幂取模)
Sum
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2633 Accepted Submission(s): 1104

1. For N = 2, S(1) = S(2) = 1.
2. The input file consists of multiple test cases.
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<cstdlib>
#include<stack>
#include<string>
#define eps 0.000000001
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int INF=0x3f3f3f3f;
const int N=+;
const ll mod=1e9+;
char str[N];
ll ksm(ll a,ll b){
ll ans=;
while(b){
if(b&){
ans=ans*a%mod;
}
b=b/;
a=a*a%mod;
}
return ans;
}
int main(){
while(gets(str)){
ll m=mod-;
ll ans=;
int len=strlen(str);
for(int i=;i<len;i++){
ans=ans*+str[i]-'';
if(ans>=m)ans=ans%m;
}
ans=(ans-+m)%m;
ll t;
t=ksm(,ans);
printf("%lld\n",t);
}
}
hdu 4704(费马小定理+快速幂取模)的更多相关文章
- 【费马小定理+快速幂取模】ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies
G. Give Candies There are N children in kindergarten. Miss Li bought them N candies. To make the pro ...
- 【2018 ICPC焦作网络赛 G】Give Candies(费马小定理+快速幂取模)
There are N children in kindergarten. Miss Li bought them N candies. To make the process more intere ...
- hdu 3037 费马小定理+逆元除法取模+Lucas定理
组合数学推推推最后,推得要求C(n+m,m)%p 其中n,m小于10^9,p小于1^5 用Lucas定理求(Lucas定理求nm较大时的组合数) 因为p数据较小可以直接阶乘打表求逆元 求逆元时,由费马 ...
- 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum
Sum Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...
- HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description Sample Input 2 Sample Outp ...
- hdu 4704 sum(费马小定理+快速幂)
题意: 这题意看了很久.. s(k)表示的是把n分成k个正整数的和,有多少种分法. 例如: n=4时, s(1)=1 4 s(2)=3 1,3 3,1 2,2 s ...
- HDU 4704 Sum( 费马小定理 + 快速幂 )
链接:传送门 题意:求 N 的拆分数 思路: 吐嘈:求一个数 N 的拆分方案数,但是这个拆分方案十分 cd ,例如:4 = 4 , 4 = 1 + 3 , 4 = 3 + 1 , 4 = 2 + 2 ...
- 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)
题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...
- hdu 4704(费马小定理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4704 思路:一道整数划分题目,不难推出公式:2^(n-1),根据费马小定理:(2,MOD)互质,则2^ ...
随机推荐
- PowerDesigner16逆向工程生成PDM列注释(My Sql5.0模版)
一.编辑当前DataBase 选择DataBase——>edit Current DBMS...弹出如下对话框: 如上图,先解释一下: 根据红颜色框从上往下解释一下. 第一个红框是对应的修改的 ...
- C# textbox 获得焦点
this.ActiveControl = txt_core;
- for mxl path
废话不多说,直接上例子 简单明了 create table tb_class ( classId int , className ) ) go ,'一班') ,'二班') ,'三班') go crea ...
- 换个语言学一下 Golang (4)——变量与常量
一.变量定义 所谓的变量就是一个拥有指定名称和类型的数据存储位置. //看一个例子 package main import ( "fmt" ) func main() { var ...
- 四、Spider用法
本文转载自以下链接: https://scrapy-chs.readthedocs.io/zh_CN/latest/topics/spiders.html https://doc.scrapy.org ...
- 03.requests模块(1)
目录 03.requests模块(1) 展开requests模块的学习 代码实例 需求:爬取搜狗指定词条搜索后的页面数据 需求:登录豆瓣电影,爬取登录成功后的页面数据 需求:爬取豆瓣电影分类排行榜 h ...
- Python基础-奇偶判断调用函数
编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数 1/1+1/3+...+1/n. 首先写一个n为偶数的函数: def peven(n): s = 0 ...
- copy the content of a file muliptle times and save as ordered files:
input: transient.case outputs: transient_1.case, transient_2.case,...transient_101.case ********** n ...
- Caused by: android.os.TransactionTooLargeException总结
错误信息 Error: android.os.TransactionTooLargeException W/ActivityManager(344): android.os.TransactionTo ...
- asp.net--解决上传文件大小限制
原文地址 第一种方法,主要适用于IIS6.0版本 一.修改配置Web.Config文件中的httpRuntime节点 对于asp.net,默认只允许上传4M文件,增加如下配置,一般可以自定义最大文件大 ...