题目链接:

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 AB,n 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 longinteger 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
  1. 3 4 1 1
output
  1. 7
input
  1. 3 4 2 1
output
  1. 25
input
  1. 3 4 3 1
output
  1. 79
  2.  
  3. 题意:
  4.  
  5. 求这个式子的值;
  6.  
  7. 思路:
  8.  
  9. 最后是一个等比数列化简一下,注意一下A==1的情况;
    ans=(A^n-1)/(A-1)*B+A^n*x;
    A==1的时候ans=n*B+x;一个大水题;
  10.  
  11. AC代码:
  1. //#include <bits/stdc++.h>
  2.  
  3. #include <iostream>
  4. #include <queue>
  5. #include <cmath>
  6. #include <map>
  7. #include <cstring>
  8. #include <algorithm>
  9. #include <cstdio>
  10. using namespace std;
  11. #define Riep(n) for(int i=1;i<=n;i++)
  12. #define Riop(n) for(int i=0;i<n;i++)
  13. #define Rjep(n) for(int j=1;j<=n;j++)
  14. #define Rjop(n) for(int j=0;j<n;j++)
  15. #define mst(ss,b) memset(ss,b,sizeof(ss));
  16. typedef unsigned long long uLL;
  17. typedef long long LL;
  18. const LL mod=1e9+;
  19. const double PI=acos(-1.0);
  20. const int inf=0x3f3f3f3f;
  21. const int N=1e6+;
  22. template<class T> void read(T&num) {
  23. char CH; bool F=false;
  24. for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
  25. for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
  26. F && (num=-num);
  27. }
  28. int stk[], tp;
  29. template<class T> inline void print(T p) {
  30. if(!p) { puts(""); return; }
  31. while(p) stk[++ tp] = p%, p/=;
  32. while(tp) putchar(stk[tp--] + '');
  33. putchar('\n');
  34. }
  35.  
  36. LL A,B,n,x;
  37.  
  38. LL fastpow(LL fx,LL fy)
  39. {
  40. LL s=,base=fx;
  41. while(fy)
  42. {
  43. if(fy&)s*=base,s%=mod;
  44. base*=base;
  45. base%=mod;
  46. fy=(fy>>);
  47. }
  48. return s;
  49. }
  50.  
  51. int main()
  52. {
  53. read(A),read(B),read(n),read(x);
  54. LL temp1=fastpow(A-,mod-),temp2=fastpow(A,n);
  55. if(A==)cout<<(n%mod*B+x)%mod<<"\n";
  56. else cout<<(temp1*(temp2-)%mod*B%mod+temp2*x%mod)%mod<<"\n";
  57.  
  58. return ;
  59. }

codeforces 678D 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/contest/678/problem/D D. Iterated Linear Function Consider a linear function f ...

  4. 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 s ...

  5. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  6. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  7. Codeforces Testing Round #12 A. Divisibility 水题

    A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  8. Codeforces Beta Round #37 A. Towers 水题

    A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...

  9. codeforces 677A A. Vanya and Fence(水题)

    题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...

随机推荐

  1. javaScript return false

    在大多数情况下,为事件处理函数返回false,可以防止默认的事件行为.例如,默认情况下点击一个<a>元素,页面会跳转到该元素href属性指定的页.  Return False 就相当于终止 ...

  2. JavaScript的因为所以

    各位看官,楼主开始说过写几篇博客,这是这个系列的最后一集.吾以为:了解JavaScript的身世之谜,掌握其近乎心想事成的变量系统,了解其解析运行的偷梁换柱之法,熟悉布大师迂回曲折的OOP实现.那你离 ...

  3. css3 过度效果之物体向上冒出

    <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"/> <meta nam ...

  4. SCCM客户端推送/卸载

    站点配置--站点--层次结构设置--自动批准客户端 ccm客户端安装日志:服务器端的ccm.log安装ccm客户端,需要添加一个具有访问客户端$admin权限的账户,如下:站点名称-右键 客户端安装设 ...

  5. 百度语音识别REST API——通过使用Http网络请求方式获得语音识别功能

    百度语音识别通过REST API的方式给开发人员提供一个通用的HTTP接口,基于该接口,开发人员能够轻松的获取语音识别能力,本文档描写叙述了使用语音识别服务REST API的方法. 长处: 较之开发人 ...

  6. Response.Redirect 打开新窗体的两种方法

    普通情况下,Response.Redirect 方法是在server端进行转向,因此,除非使用 Response.Write("<script>window.location=' ...

  7. 10 款精美的 CSS3 全新特效

    大家都知道,在网页制作时使用CSS技术,可以有效地对页面的布局.字体.颜色.背景和其它效果实现更加精确的控制.只要对相应的代码做一些简单的修改,就可以改变同一页面的不同部分,或者页数不同的网页的外观和 ...

  8. oracle 迁移到 mysql(结构和数据)

    1下载MySQL Migration Toolkit 2安装:jdk-6u38-ea-bin-b04-windows-amd64-31_oct_2012.exe 3下载ojdbc14.jar 具体地址 ...

  9. 微信公共服务平台开发(.Net 的实现)8-------处理图片(上传下载发送)

    举个例子,有人对着我们的公共微信号拍个照片发送过来,然后我们处理这个照片,比如进行ocr识别字(随后就会降到这个例子),或者人脸识别,或者拍照取证等,这些功能都是相当有用的.那么我们现在就要分析一下这 ...

  10. 【JavaScript】apply和call的区别在哪?

    我在一开始看到javascript的函数apply和call时,非常的模糊,看也看不懂,最近在网上看到一些文章对apply方法和call的一些示例,总算是看的有点眉目了,在这里我做如下笔记,希望和大家 ...