Input

2

Output

2

Hint

1. For N = 2, S(1) = S(2) = 1. 2. The input file consists of multiple test cases.

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. 

 归律是2的n-1次方但是n太大就用到了欧拉降幂

和之前的一道题很想,之前的是2的n次方https://blog.csdn.net/lbperfect123/article/details/86693581

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath> const int maxn=1e5+5;
const int mod=1e9+7;
typedef long long ll;
using namespace std; char a[100005];
ll x,z=mod;
ll quickpow(ll x,ll y,ll z)
{
ll ans=1;
while(y)
{
if(y&1)
ans=ans*x%z;
x=x*x%z;
y>>=1;
}
return ans;
}
ll phi(ll n)
{
ll i,rea=n;
for(i=2;i*i<=n;i++)
{
if(n%i==0)
{
rea=rea-rea/i;
while(n%i==0)
n/=i;
}
}
if(n>1)
rea=rea-rea/n;
return rea;
}
int main()
{
while(scanf("%s",a)!=EOF)
{
ll len=strlen(a);
ll p=phi(z);
ll ans=0;
for(ll i=0;i<len;i++)
ans=(ans*10+a[i]-'0')%p;
ans+=p;
printf("%lld\n",quickpow(2,ans-1,z));
}
return 0;
}

Sum(欧拉降幂+快速幂)的更多相关文章

  1. CF思维联系– CodeForces -CodeForces - 992C Nastya and a Wardrobe(欧拉降幂+快速幂)

    Nastya received a gift on New Year - a magic wardrobe. It is magic because in the end of each month ...

  2. hdu 3307 Description has only two Sentences (欧拉函数+快速幂)

    Description has only two SentencesTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...

  3. XMU 1615 刘备闯三国之三顾茅庐(三) 【欧拉函数+快速幂+欧拉定理】

    1615: 刘备闯三国之三顾茅庐(三) Time Limit: 1000 MS  Memory Limit: 128 MBSubmit: 45  Solved: 8[Submit][Status][W ...

  4. 【BZOJ 1409】 Password 数论(扩展欧拉+矩阵快速幂+快速幂)

    读了一下题就会很愉快的发现,这个数列是关于p的幂次的斐波那契数列,很愉快,然后就很愉快的发现可以矩阵快速幂一波,然后再一看数据范围就......然后由于上帝与集合对我的正确启示,我就发现这个东西可以用 ...

  5. 数学知识-欧拉函数&快速幂

    欧拉函数 定义 对于正整数n,欧拉函数是小于或等于n的正整数中与n互质的数的数目,记作φ(n). 算法思路 既然求解每个数的欧拉函数,都需要知道他的质因子,而不需要个数 因此,我们只需求出他的质因子, ...

  6. 牛客训练:小a与黄金街道(欧拉函数+快速幂)

    题目链接:传送门 思路:欧拉函数的性质:前n个数的欧拉函数之和为φ(n)*n/2,由此求出结果. 参考文章:传送门 #include<iostream> #include<cmath ...

  7. Exponial (欧拉定理+指数循环定理+欧拉函数+快速幂)

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=2021 Description Everybody loves big numbers ...

  8. 小a与黄金街道(欧拉函数+快速幂)

    链接:https://ac.nowcoder.com/acm/contest/317/D 来源:牛客网 题目描述 小a和小b来到了一条布满了黄金的街道上.它们想要带几块黄金回去,然而这里的城管担心他们 ...

  9. hdu4549 矩阵快速幂 + 欧拉降幂

    R - M斐波那契数列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit  ...

随机推荐

  1. maven配置logback

    [背景] 刚接触大数据项目,在生产环境中经常需要使用日志来判定一些问题的原因. 一直以来都在使用System.out.println的标准输出来往控制台上打印日志.这种方法对性能影响很大不说,查看日志 ...

  2. [GO]结构体的值传递和地址传递

    package main import "fmt" type student struct { id int name string sex byte age int addr s ...

  3. java.lang.ClassCastException: com.liuyang.annocation.UserAction cannot be cast to com.liuyang.annocation2.UserAction at com.liuyang.annocation2.App.test

    java.lang.ClassCastException: com.liuyang.annocation.UserAction cannot be cast to com.liuyang.annoca ...

  4. linux命令的笔记

    1.改变目录的用户组和所有者 chown 命令 如下图: 可以看到test1与test2的的所有者和所属组都是root,其中 第三个字段是说明目录拥有者, 第四个字段是文件拥有者所在的组, 第五个字段 ...

  5. java修饰符 protect public protected

    1.private修饰词,表示成员是私有的,只有自身可以访问: 2.protected,表示受保护权限,体现在继承,即子类可以访问父类受保护成员(子类是可以访问父类的带protected修饰符的成员的 ...

  6. Android dex分包方案和热补丁原理

    一.分包的原因: 当一个app的功能越来越复杂,代码量越来越多,也许有一天便会突然遇到下列现象: 1. 生成的apk在2.3以前的机器无法安装,提示INSTALL_FAILED_DEXOPT 2. 方 ...

  7. git command cheat sheet

    clone:克隆 --non-bare:(默认值)一般的克隆方式 --bare:只克隆.git目录 --mirror:只克隆.git目录,并且还保持与origin的关联,可以fetch commit: ...

  8. Linux常用开发指令

    gcc mysqltest.c -o mysqltest `mysql_config –cflags –libs`

  9. Jenkins Pipeline+Maven+Gitlab持续集成构建问题集锦

    问题 1.全局配置一定要写正确,之前where git 给的地址时E:\Git\cmd\git.exe一直报错,其实Windows真正的git.exe在bin目录下 如果是Linux中,使用where ...

  10. PLSQL Developer 13.0.0.1883 注册码

    PLSQL Developer 13.0.0.1883 注册码 product code: 4vkjwhfeh3ufnqnmpr9brvcuyujrx3n3le serial Number:22695 ...