Description

Let {xi} be the infinite sequence of integers: 
1) x0 = A; 
2) xi = (alpha * xi-1^2 + beta * xi-1 + gamma) mod M, for i >= 1. 
Your task is to find xk if you know A, alpha, beta, gamma, M and k.

Input

Given A (1 <= A <= 10000), alpha (0 <= alpha <= 100), beta (0 <= beta <= 100), gamma (0 <= gamma <= 100), M (1 <= M <= 1000), k (0 <= k <= 10^9). All numbers are integer.

Output

Write xk.

Sample Input

Input
 
 
1 1 1 1 10 1
 
 
Output
 
 
3
 

/**********************
打表观察,一个周期问题,暴力找周期 ,巧用map找周期
********************************/
#include"iostream"
#include"map"
#include"cstdio"
using namespace std;
const int ms=;
int T,begin,A,a,b,c,m,k;
void find()
{
map<int, int> mp;
//map[0]=A;
mp[]=A;
int tmp=A;
for(int i=;i<=ms;i++)
{
tmp=(a*tmp*tmp+b*tmp+c)%m;
if(mp[tmp])
{
begin=mp[tmp];
T=i-mp[tmp];
break;
}
else
{
mp[tmp]=i;
}
}
}
int main()
{
scanf("%d%d%d%d%d%d",&A,&a,&b,&c,&m,&k);
find();
int ans;
if(k<begin)
{
ans=A;
for(int i=;i<=k;i++)
ans=((long long)a*ans*ans+b*ans+c)%m;
cout<<ans<<endl;
}
else
{
k-=begin;k%=T;ans=A;
for(int i=;i<=begin+k;i++)
{
ans=(a*ans*ans+b*ans+c)%m;
}
cout<<ans<<endl;
}
return ;
}

X-Sequence的更多相关文章

  1. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  2. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  3. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  6. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  10. Leetcode 60. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

随机推荐

  1. HDU5479 Colmerauer 单调栈+暴力优化

    http://acm.hdu.edu.cn/showproblem.php?pid=5749 思路: bestcoder 84 贡献:所有可能的子矩阵的面积和 //len1:子矩阵所有长的和 ;i&l ...

  2. sf空间配置

    1.创建VHost     记住Homepage,打开VHost DNS标签页,创建Virtual Host,如下图: 2.Wcp上传文件     用户名是"sf用户名,sf项目名" ...

  3. <Chapter 2>2-1-2.安装Java SDK

    Java运行时环境的App Engine SDK运行在任何运行了Java SE开发工具(JDK)的电脑上.Java SDK App Engine 支持JDK 6,并且当运行App Engine的时候, ...

  4. hadoop HDFS 写入吞吐量

    最近一个项目 在大把大把的使用hadoop-HDFS,关于HDFS 的优势网上都快说烂了,这里不再说了,免得被.. 呵呵 废话少说,开整 1.场景描述: 服务器A 监听 服务器B分发任务socket. ...

  5. C++问题-Qt Visual Studio Add-in

    问题现象:用VS打开其他人的项目提示如下:Qt Visual Studio Add-in...中间全TMD的英文,我就省略...QT版本不对,需要修改QT版本. 问题原因:占时不明,因为我是开发Del ...

  6. Cognos 增加全局类

    Cognos使用版本10.1.1 由于我服务器装的是linux系统下的,所以window系统下的方法,提一下,但是没有实现过. 1.Linux系统下增加全局类 ●修改GlobalReportStyle ...

  7. Linux递归删除文件命令

    Linux递归删除文件命令 find . -name "*.log.*" -exec ls {} \; find . -name "*.log.*" -exec ...

  8. HDU 4432 Sum of divisors (水题,进制转换)

    题意:给定 n,m,把 n 的所有因数转 m 进制,再把各都平方,求和. 析:按它的要求做就好,注意的是,是因数,不可能有重复的...比如4的因数只有一个2,还有就是输出10进制以上的,要用AB.. ...

  9. 用Swashbuckle给ASP.NET Core的项目自动生成Swagger的API帮助文档

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:用Swashbuckle给ASP.NET Core的项目自动生成Swagger的API帮助文档.

  10. securecrt 连接vmware ubuntu

    折腾了好几天,我只想说shit,吃一堑长一智,和大家分享. SecureCRT连接Linux是使用Ubuntu下的SSH服务,ssh包括客户端和服务端即openssh-client,openssh-s ...