Educational Codeforces Round 13 D. Iterated Linear Function 逆元+公式+费马小定理
1 second
256 megabytes
standard input
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 A, B, n and x find the value of g(n)(x) modulo 109 + 7.
The only line contains four integers A, B, n 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.
Print the only integer s — the value g(n)(x) modulo 109 + 7.
3 4 1 1
7
3 4 2 1
25
3 4 3 1
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 逆元+公式+费马小定理的更多相关文章
- Educational Codeforces Round 13 D. Iterated Linear Function 水题
D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...
- 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 ...
- Educational Codeforces Round 13 D. Iterated Linear Function (矩阵快速幂)
题目链接:http://codeforces.com/problemset/problem/678/D 简单的矩阵快速幂模版题 矩阵是这样的: #include <bits/stdc++.h&g ...
- Educational Codeforces Round 13 D:Iterated Linear Function(数论)
http://codeforces.com/contest/678/problem/D D. Iterated Linear Function Consider a linear function f ...
- CodeForces 300C Beautiful Numbers(乘法逆元/费马小定理+组合数公式+高速幂)
C. Beautiful Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- codeforces div2_604 E. Beautiful Mirrors(期望+费马小定理)
题目链接:https://codeforces.com/contest/1265/problem/E 题意:有n面镜子,你现从第一面镜子开始询问,每次问镜子"今天我是否美丽",每天 ...
- 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 ...
- Educational Codeforces Round 13 E. Another Sith Tournament 状压dp
E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...
- Educational Codeforces Round 13 C. Joty and Chocolate 水题
C. Joty and Chocolate 题目连接: http://www.codeforces.com/contest/678/problem/C Description Little Joty ...
随机推荐
- 作为小白该如何抉择python编辑器?
刚开始接触编程,有一个好的编辑器上手,那学习起来肯定是事半功倍的!本篇就给大家介绍适合零基础小白学习Python的四种编辑器,希望大家受用! 1.Sublime Text: 这是一个轻量级的代码编辑器 ...
- C# 批量设置窗体中控件状态的方法
在开发中常遇到当点击某个按钮的时候,禁用文本框或按钮的的状态,以防止误操作,下面的代码是我已批量设置指定控件中的按钮状态的代码,同理可以延伸出很多操作. /// <summary> /// ...
- 手机号码归属地查询API
<?php function object_array($array){ if(is_object($array)){ $array = (array)$array; } if(is_array ...
- sql游标循环
DECLARE @begindate DATETIME=CONVERT(DATETIME, '2019.05.06 09:40:50') ,@enddate DATETIME =GETDATE() , ...
- GC原理图
GC原理图,Jdk1.6及以下版本 永久代 永久代是Hotspot虚拟机特有的概念,是方法区的一种实现,别的JVM都没有这个东西.在Java 8中,永久代被彻底移除,取而代之的是另一块与堆不相连的本地 ...
- echarts —— tooltip 鼠标悬浮显示提示框属性
最近一直在使用echarts,当然也被其中的各种属性整的头大,记录一下其中遇到的问题. tooltip:鼠标悬浮时显示的提示框. 今天想要记录的是[自定义提示框的内容],如下图,鼠标悬浮时提示框内显示 ...
- es 启动报错 内存太小
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] elastics ...
- kubernetes之node隔离与恢复
需求: 在硬件升级, 硬件维护等情况下, 我们需要将某些node隔离, kubectl cordon <node_name> #禁止pod调度到该节点上, 在其上运行的pod并不会自动停止 ...
- 002.MVC开发方法和步骤--用一个简单的加法程序来演示
MVC的工作原理: 注:ASP.NET MVC中的url 特殊:构成 http//....../控制器名/方法名 默认: 1.Url请求直接来到Controller中 2.Controller从Mod ...
- ARM体系结构与编程读书笔记——处理器的运行模式
ARM处理器共有7种运行模式,如下表: 处理器模式 描述 用户模式(User, usr) 正常程序执行的模式 快速中断模式(FIQ, fiq) 用于高速数据传输和通道处理 外部中断模式(IRQ, ir ...