D. Iterated Linear Function
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x))for n > 0. For the given integer values ABn and x find the value of g(n)(x) modulo 109 + 7.

Input

The only line contains four integers ABn and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.

Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Output

Print the only integer s — the value g(n)(x) modulo 109 + 7.

Examples
input
3 4 1 1
output
7
input
3 4 2 1
output
25
input
3 4 3 1
output
79
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a,b) memset(a,b,sizeof(a))
#define SC scanf
#define PF printf
#define CT continue
typedef long long ll;
typedef unsigned long long ULL;
const int mod = ;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const int N=*1e5+; ll quick(ll a,ll n)
{
ll res=;
while(n){
if(n&) res=(res*a)%mod;
a=(a*a)%mod;
n>>=;
}
return res;
} ll yuan(ll n)
{
return quick(n,mod-);
} int main()
{
ll a,b,n,x;
while(~SC("%lld%lld%lld%lld",&a,&b,&n,&x)){
ll ans=;
ans+=quick(a,n)*x%mod;
ans+=b*(quick(a,n)-)%mod*yuan(a-)%mod;
PF("%lld\n",ans);
}
return ;
}

逆元求法:利用费马小定理

http://blog.csdn.net/qq_21057881/article/details/51758437

Educational Codeforces Round 13 D. Iterated Linear Function 逆元+公式+费马小定理的更多相关文章

  1. Educational Codeforces Round 13 D. Iterated Linear Function 水题

    D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...

  2. Educational Codeforces Round 13——D. Iterated Linear Function(矩阵快速幂或普通快速幂水题)

      D. Iterated Linear Function time limit per test 1 second memory limit per test 256 megabytes input ...

  3. Educational Codeforces Round 13 D. Iterated Linear Function (矩阵快速幂)

    题目链接:http://codeforces.com/problemset/problem/678/D 简单的矩阵快速幂模版题 矩阵是这样的: #include <bits/stdc++.h&g ...

  4. Educational Codeforces Round 13 D:Iterated Linear Function(数论)

    http://codeforces.com/contest/678/problem/D D. Iterated Linear Function Consider a linear function f ...

  5. CodeForces 300C Beautiful Numbers(乘法逆元/费马小定理+组合数公式+高速幂)

    C. Beautiful Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  6. codeforces div2_604 E. Beautiful Mirrors(期望+费马小定理)

    题目链接:https://codeforces.com/contest/1265/problem/E 题意:有n面镜子,你现从第一面镜子开始询问,每次问镜子"今天我是否美丽",每天 ...

  7. Educational Codeforces Round 13 A、B、C、D

    A. Johny Likes Numbers time limit per test 0.5 seconds memory limit per test 256 megabytes input sta ...

  8. Educational Codeforces Round 13 E. Another Sith Tournament 状压dp

    E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...

  9. Educational Codeforces Round 13 C. Joty and Chocolate 水题

    C. Joty and Chocolate 题目连接: http://www.codeforces.com/contest/678/problem/C Description Little Joty ...

随机推荐

  1. 使用JavaScript随机生成数字混合字母的验证码

      <script> // 封装一个随机生成数字的函数 function random(a, b) { var n = Math.round(Math.random() * (a - b) ...

  2. git 使用中报错:LF will be replaced by CRLF in app.json

    git config --global core.autocrlf false //禁用自动转换

  3. hdu 1502 大数dp

    对于每一个dp的问题 从其最优解的结构(分哪几种形式或者情况)入手 然后分析状态 这样就比较好找出状态转方程这里数据结构的选择很简单 顺序数组就可以 填充的方式顺序填充就可以 然后这道题目卡了我大数. ...

  4. asp.net core In Docker(Image)

    原文地址:https://www.cnblogs.com/stulzq/p/9059108.html 大家应该知道目前.NET Core(2.0)还是没有System.Drawing程序集,如果我们要 ...

  5. C#使用phantomjs,爬取AJAX加载完成之后的页面

    1.开发思路:入参根据apiSetting配置文件,分配静态文件存储地址,可实现不同站点的静态页生成功能.静态页生成功能使用无头浏览器生成,生成之后的字符串进行正则替换为固定地址,实现本地正常访问. ...

  6. 在开源UOJ的导航栏中添加新页面链接

    前言 刚用开源UOJ搭建OJ成功时就想在导航栏那里添加一个站内页面链接,无奈当时乱搞水平低,网上也没有教程,不晓得怎么弄 今天突然来了闲情乱搞一通,结果还真乱搞成了...特意写下为后来人少走点弯路 前 ...

  7. python numpy 删除array指定位置的元素

    如图:设计一个数组或者tuple,其中的元素是True或False,那么在False位置上的元素就会被删掉 索引的元素还可以是int型的数,这时候就代表,将原来的数组中指定位置的数放在当前的位置,且索 ...

  8. SQL将多行数据合并成一行【转】

    转:https://blog.csdn.net/AntherFantacy/article/details/83824182 今天同事问了一个需求,就是将多行数据合并成一行进行显示,查询了一些资料,照 ...

  9. Docker搭建Gitlab代码管理平台

    一.Gitlab的安装 宿主机环境: CentOS 7 docker docker-compose 1.查找镜像 docker search gitlab 2.拉取镜像 docker pull git ...

  10. 使用python+selenium获得b站今日播放的动漫

    from selenium import webdriver browser=webdriver.Chrome() browser.get('https://www.bilibili.com/anim ...