Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3245    Accepted Submission(s): 1332

Problem Description

 

Sample Input

2
 

Sample Output

2

Hint

1. For N = 2, S(1) = S(2) = 1.

2. The input file consists of multiple test cases.

 

Source

 
模型最终转换为求2^(b-1) mod (1e9+7),根据费马小定理可得1e9+7的欧拉函数为1e9+6。根据欧拉降幂公式a^b = a^(b%phi(MOD)+phi(MOD)) mod MOD,用快速幂算出a^(b%phi(MOD)+phi(MOD))即为答案。
 //2017-08-04
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long using namespace std; const int N = ;
const int MOD = ;
char str[N]; ll quick_pow(ll a, ll n){//快速幂
ll ans = ;
while(n){
if(n&)ans = ans*a%MOD;
a = a*a%MOD;
n>>=;
}
return ans;
} int main()
{
while(scanf("%s", str)!=EOF){
ll num = ;
for(int i = ; i < strlen(str); i++){//欧拉降幂
num *= ;
num += str[i]-'';
num %= (MOD-);
}
num -= ;
printf("%lld\n", quick_pow(, num));
} return ;
}

HDU4704(SummerTrainingDay04-A 欧拉降幂公式)的更多相关文章

  1. HDU4704:Sum(欧拉降幂公式)

    Input 2 Output 2 Sample Input 2 由公式,ans=2^(N-1)%Mod=2^((N-1)%(Mod-1)+(Mod-1)) %Mod. 注意:降幂的之后再加一个Mod- ...

  2. bzoj3884: 上帝与集合的正确用法 欧拉降幂公式

    欧拉降幂公式:http://blog.csdn.net/acdreamers/article/details/8236942 糖教题解处:http://blog.csdn.net/skywalkert ...

  3. D - Power Tower欧拉降幂公式

    题意:给你一个数组a,q次查询,每次l,r,要求 \(a_{l}^{a_{l+1}}^{a_{l+2}}...{a_r}\) 题解:由欧拉降幂可知,最多log次eu(m)肯定变1,那么直接暴力即可,还 ...

  4. Applese涂颜色-欧拉降幂公式

    链接:https://ac.nowcoder.com/acm/contest/330/E来源:牛客网 题目描述 精通程序设计的 Applese 叕写了一个游戏. 在这个游戏中,有一个 n 行 m 列的 ...

  5. 2018牛客网暑期ACM多校训练营(第四场) A - Ternary String - [欧拉降幂公式][扩展欧拉定理]

    题目链接:https://www.nowcoder.com/acm/contest/142/A 题目描述 A ternary string is a sequence of digits, where ...

  6. 牛客OI测试赛 F 子序列 组合数学 欧拉降幂公式模板

    链接:https://www.nowcoder.com/acm/contest/181/F来源:牛客网 题目描述 给出一个长度为n的序列,你需要计算出所有长度为k的子序列中,除最大最小数之外所有数的乘 ...

  7. 欧拉降幂公式 Super A^B mod C

    Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=100000 ...

  8. FZU1759(SummerTrainingDay04-B 欧拉降幂公式)

    Problem 1759 Super A^B mod C Accept: 1056    Submit: 3444Time Limit: 1000 mSec    Memory Limit : 327 ...

  9. TOJ 3151: H1N1's Problem(欧拉降幂)

    传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=3151 时间限制(普通/Java): ...

随机推荐

  1. HttpInvokerUtils

    package com.sprucetec.tms.utils; import org.slf4j.Logger;import org.slf4j.LoggerFactory; import java ...

  2. Data - Hadoop单机配置 - 使用Hadoop2.8.0和Ubuntu16.04

    系统版本 anliven@Ubuntu1604:~$ uname -a Linux Ubuntu1604 4.8.0-36-generic #36~16.04.1-Ubuntu SMP Sun Feb ...

  3. java中身份证号和的银行卡的深度校验

    一: 身份证号: package com.mobile.utils; import java.text.SimpleDateFormat; import java.util.Calendar; imp ...

  4. C、C++打包成.dll .so .a 给Unity使用

    C.C++打包成.dll .so .a 给Unity使用 打包.dll库 工具:VS 使用VS新建项目 选择不大于.NET3.5的版本 选择Visual C++ -> Win32 控制台应用程序 ...

  5. vue教程2-02 vue防止花括号{{}}闪烁,v-text和v-html、v-cloak

    vue教程2-02 vue防止花括号{{}}闪烁,v-text和v-html.v-cloak 一.v-text和v-html <span>{{msg}}</span>  --& ...

  6. vs 2017 IIS EXPRESS 增加局域网访问

    在VS调试站点,默认使用IISExpress,locall+端口,为了使用IP地址.多域名调试,找到 IISExpress下的applicationhost.config,在目标站点下增加类似行: & ...

  7. ASP.NET Core 1.0 基础与应用启动

    .NET Core http://dotnet.github.io/[https://github.com/dotnet/coreclr] ASP.NET Core 1.0 https://get.a ...

  8. Android中实现activity的页面跳转并传值

    一个Android应用程序很少会只有一个Activity对象,如何在多个Activity之间进行跳转,而且能够互相传值是一个很基本的要求. 本次我们就讲一下,Android中页面跳转以及传值的几种方式 ...

  9. Intellij IDEA Spring Boot 项目Debug模式启动缓慢问题

    问题 Intellij IDEA Spring Boot 项目Debug模式启动缓慢 环境 os: windows10 idea :2018.1 解决方法 去除所有断点就正常了,很诡异,原因未知.

  10. 面试:vector类的简单实现

    vector类的简单实现 #include <vector> #include <iostream> #include <cstring> #include < ...