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^ ...
随机推荐
- html5——3D转换
角度旋转 rotateX:默认以center绕x轴旋转 rotateY:默认以center绕y轴旋转 rotateZ:默认以cente绕z轴r旋转 //rotateX原点为center==>正值 ...
- 【译】x86程序员手册17-第6章保护
Chapter 6 Protection 第六章 保护 6.1 Why Protection? 为什么要保护? The purpose of the protection features of th ...
- jstree CHECKBOX PLUGIN
The checkbox plugin makes multiselection possible using three-state checkboxes. Configuration overri ...
- 抓包工具Fiddler及Charles
一.抓包工具介绍 1.charles抓包如何抓取手机端数据包(安卓手机) (1)获取pc的IP地址 (2)打开charles里的[Proxy]-[Proxy setting],设置端口号,默认为888 ...
- 原生js实现瀑布流效果
参考此篇:https://segmentfault.com/a/1190000012621936 以下为个人测试中: css: .masonry{ width:100%; } .item{ posit ...
- EF-Lamdba
一丶基本语法 var userList=db.set<table>().where(c=>c.id=="001"&&c.userName.Cont ...
- 面试bb
1.面试者进行自我介绍 2.学校/学历/大学生活及课程的心得总结(人品,性格评估) 3.技能介绍(是否对应聘工作有帮助,评估学习能力):编程/操作系统/测试工具/测试方法/脚本 4.离职原因/项目经验 ...
- 五、Scrapy中Item Pipeline的用法
本文转载自以下链接: https://scrapy-chs.readthedocs.io/zh_CN/latest/topics/item-pipeline.html https://doc.scra ...
- Swoole 源码分析——Server模块之Worker事件循环
swManager_loop 函数 manager 进程管理 manager 进程开启的时候,首先要调用 onManagerStart 回调 添加信号处理函数 swSignal_add,SIGTERM ...
- Python - 模块(一)
目录 Python - 模块(一) 模块的引用方式 常用模块 random(随机模块) os模块 sys 序列化模块 hashlib subprocess optparse struct Python ...