Plant(快速幂+数学分析(没想到吧,数学无处不在))

简介: Plant(快速幂+数学分析(没想到吧,数学无处不在))

Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.

9e26f70ffa47e84a21896cccce77c49e.png


Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.


Input


The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew.


Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.


Output


Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).


Examples


Input


1

Output


3

Input


2

Output


10

Note


The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.


题意分析得到公式2^n(2^n+1)/2第n年的向下的个数,这个要自己推了,然后用快速幂通过n得到2^n。对了,提醒一下会爆int,用long long来存。



听懂了记得给个赞鼓励一下,码字不易,用爱发电。


上ac代码。

f58230e9f063709cf3167704f4efdf14.gif


有事你就q我;QQ2917366383


学习算法

#include<iostream>
const int mod=1e9+7;
#define  ll long long
using namespace std;
ll gg(ll a,ll b,ll c)
{
  int ans=1;
  while(b)
  {
    if(b&1)
    {
      ans=ans*a%c;
    }
    a=a*a%c;
    b>>=1;
  }
  return ans;
}
int main()
{
  ll t;
  cin>>t;
ll x=gg(2,t,mod);
cout<<x*(x+1)/2%mod<<endl; 
} 




相关文章
|
Web App开发
在 HTML 中禁用 Chrome 浏览器的 Google 翻译功能
在 html 标签中添加 translate=“no” 属性,浏览器将不会翻译整个页面。
1595 0
|
安全 小程序 物联网
WLAN基础 无线局域网配置方法 旁挂三层组网隧道转发方式配置
WLAN基础 无线局域网配置方法 旁挂三层组网隧道转发方式配置
2621 0
WLAN基础 无线局域网配置方法 旁挂三层组网隧道转发方式配置
|
人工智能 数据可视化 算法
FISSPACE 技术白皮书节选|因果自导机制(Causal Self-Guidance Mechanism)
FISSPACE提出因果自导机制(CSG),让智能体从被动训练迈向自主演化。通过内部能量流、压痕反馈与因果梯度闭环,构建具备自我修正与成长能力的智能系统,实现无外部奖励下的内驱进化,推动AI走向具有方向与意志的自演化时代。(238字)
697 1
|
7月前
|
设计模式 人工智能 JSON
Agent Skill规范、构建与设计模式
文章从 Skill 的规范格式、三层渐进式加载机制、模型驱动触发逻辑出发,深入解析 Skill-Creator 的工程化开发范式。(文章内容基于作者个人技术实践与独立思考,旨在分享经验,仅代表个人观点。)
6942 5
Agent Skill规范、构建与设计模式
|
9月前
|
人工智能 监控 数据可视化
保姆级教程:OpenClaw阿里云部署+免费大模型API配置+18个必装神级Skills实战及避坑手册
本文基于18个神级技能精选逻辑,补充2026年新手零基础阿里云部署流程、阿里云百炼API及免费大模型API双配置方案,按“金融分析、信息获取、财务数据、办公协同”四大场景拆解技能用法,所有代码命令可直接复制执行,帮助用户快速解锁OpenClaw的全能属性,让效率直接翻10倍。
2508 7
|
SQL 存储 关系型数据库
MySQL为什么被广泛使用
MySQL凭借其卓越的技术特性、成熟的开源生态和持续创新,成为数据库领域领军者。它以高性能、高可用性和广泛的社区支持,赢得从初创公司到世界500强企业的广泛采用。本文深入解析MySQL持续成功的背后原因。
|
机器学习/深度学习 开发工具 计算机视觉
YOLOv8 目标检测 | 自定义数据集
YOLOv8 目标检测 | 自定义数据集
|
SQL 数据采集 数据可视化
Pandas 数据结构 - DataFrame
10月更文挑战第26天
1215 2
Pandas 数据结构 - DataFrame
|
算法 关系型数据库 MySQL
MySQL高级篇——排序、分组、分页优化
排序优化建议、案例验证、范围查询时索引字段选择、filesort调优、双路排序和单路排序、分组优化、带排序的深分页优化
MySQL高级篇——排序、分组、分页优化
|
Prometheus 监控 Cloud Native
基于Docker安装Grafana和Prometheus
Grafana 是一款用 Go 语言开发的开源数据可视化工具,支持数据监控和统计,并具备告警功能。通过 Docker 部署 Grafana 和 Prometheus,可实现系统数据的采集、展示和告警。默认登录用户名和密码均为 admin。配置 Prometheus 数据源后,可导入主机监控模板(ID 8919)进行数据展示。
1558 4