X-Sequence
Description
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
Output
Sample Input
/**********************
打表观察,一个周期问题,暴力找周期 ,巧用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的更多相关文章
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [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 ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- 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 ...
随机推荐
- 搜狐云景paas平台实践之路
前言: 搜狐云景作为搜狐的paas平台,在2014年5月22日的云计算大会上正式发布了公测.初测,注册用户必须先申请邀请码参与公测会赠送用户100元电子券,经过实名认证之后会再赠送100电子券,目测可 ...
- 用Intellij Idea创建简单的Servlet
Servlet作为Java服务端程序,使用起来还是挺方便的,下面是具体配置过程,我用的是Intellij Idea. 1. 做好必要准备,Intellij Idea(或者Eclipse for J2E ...
- 阿里云slb http https配置
- javascript !!作用
javaScript中使用!!表示取得boolean值,具体作用如下 var value= !!test[1]; 取变量的Boolean值, 相当于 var value = test[1]?true: ...
- work4
任务概述 给出多条英文单词,找出一个包含所有单词的填字阵.并且对于该方阵有一定特殊要求: a) Stage 1 Every phrase in the input file is cover ...
- DelphiXE7中创建WebService(服务端+客户端)
相关资料: http://www.2ccc.com/news/Html/?1507.html http://www.dfwlt.com/forum.php?mod=viewthread&tid ...
- Spring AOP Interceptor transaction is not working
Problem The Spring AOP transaction is not working in following interceptors? <bean id="testA ...
- 搭建nodejs环境推荐用两个工具:nvm和npm
nvm 是 nodejs version manager 的简称,即:nodejs版本管理npm 是 nodejs package manager 的简称,即:nodejs模块管理 有了这两个工具,管 ...
- mysql和oracle日期和字符相互转换
一.mysql日期和字符相互转换 1.1.日期——>字符 date_format(date,'%Y-%m-%d') oracle中的to_char(); 1.2.字符——> ...
- session cookie原理及应用
一.术语session在我的经验里,session这个词被滥用的程度大概仅次于transaction,更加有趣的是transaction与session在某些语境下的含义是相同的. session,中 ...