2013年3月百度之星A题

伪随机数生成器

题目描述

 baidu熊最近在学习随机算法,于是他决定自己做一个随机数生成器。

这个随机数生成器通过三个参数c, q, n作为种子, 然后它就可以通过以下方式生成伪随机数序列:

m0c,

mi+1= (q2mi + 1) mod 2n,    for all i >= 0.

 

因为一些奇怪的原因,q 一定是奇数。现在du熊想知道对于一个给定的数 x ,是不是会出现在这个伪随机数序列里面,如果存在的话,他还想知道最早是在哪里出现,即给定一个整数 x ,要求找出一个最小的整数 k 满足 mkx.

输入格式

输入包含多组数据。

每个测试数据包含一行三个整数: c, q, n, x.

数据满足0 <= c < 2n, 0 <= q2 < 263, 0 < n <= 63, 0 <= x < 263.

输入以文件结束符结尾。

输出格式

对应每个测试数据输出满足条件的k,如果x不会出现在序列里面的话,就输出-1。

样例输入
1 3 3 5
1 3 2 5
样例输出
4
-1

这道题第一感觉觉得应该是用费马小定理或者欧拉定理之类的东西,再分析递推,后来才发现想错了,浪费了很多时间,暂时也不知道代码写的对不对,测试了几组都是对的,到时候确认了再发代码吧。

很容易知道循环节是2^n,白晔说当n充分小的时候,Mi=i+c(mod2^n).........如果n过大,就得加上一个2^m。。那是不是不会通过所有的数据。。。

 

转载于:https://www.cnblogs.com/whatthefy/archive/2013/03/30/2991025.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/274301.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

为什么张扬的人别人很讨厌_为什么每个人总是讨厌重新设计,即使他们很好

为什么张扬的人别人很讨厌重点 (Top highlight)微处理 (Microprocessing) In Microprocessing, columnist Angela Lashbrook aims to improve your relationship with technology every week. Microprocessing goes deep on the little things that define your online life to…

转载--C语言:浮点数在内存中的表示

单精度浮点数&#xff1a; 1位符号位 8位阶码位 23位尾数 双精度浮点数&#xff1a; 1位符号位 8位阶码位 52位尾数 实数在内存中以规范化的浮点数存放&#xff0c;包括数符、阶码、尾数。数的精度取决于尾数的位数。比如32位机上float型为23位 double型为52位。…

学习ui设计_如果您想学习UI设计,该怎么办

学习ui设计There is a question that is always asked when we want to learn something new.当我们想学习新东西时&#xff0c;总会问一个问题。 Where to start?从哪儿开始&#xff1f; This is also being my question when I want to learn UI design. In this article, …

Christmas

html5 game - Christmasloading......转载于:https://www.cnblogs.com/yorhom/archive/2013/04/05/3001116.html

30个WordPress Retina(iPad)自适应主题

原文地址&#xff1a;http://www.goodfav.com/zh/retina-ready-wordpress-themes-3556.html WordPress Retina定制主题进行了优化&#xff0c;支持Retina屏幕上的高品质和清晰的图像。如果你关心这个话题&#xff0c;又不知道这究竟是什么&#xff0c;那么请你继续阅读。 wordp…

Thinking in java第一章对象导论

这一章&#xff0c;做笔记感觉不是很好做。每个人又每个人对面向对象的理解。这里说一下书里的关键字&#xff0c;穿插一下自己的思想 面向对象的编程语言里面很流行的一句话&#xff0c;一切都是对象。面向对象的核心就是抽象&#xff0c;抽象的能力有大有小&#xff0c;是决定…

Android SlidingMenu插件的使用

1、在github上下载了源码后 不知道如何使用&#xff0c;在折腾了一个晚上后终于弄好了 下载地址 https://github.com/jfeinstein10/SlidingMenu 下载完后&#xff0c;解压&#xff0c;然后先import 其中的library &#xff0c;然后把项目名改为SlidingMenu 2、然后再到http…

css 字体字体图标_CSS基础知识:了解字体

css 字体字体图标In this tutorial, we’ll be learning about working with fonts in CSS!在本教程中&#xff0c;我们将学习有关在CSS中使用字体的知识&#xff01; The font property is a shorthand property which can combine a number of sub-properties in a single d…

openstack quantum搭建过程中一些有用的链接

OpenvSwitch的概念和流程&#xff1a; http://blog.wachang.net/2013/03/openvswitch-fullbook-2-workflow-1/ OpenvSwitch的vlan模式&#xff1a; http://openvswitch.org/support/config-cookbooks/vlan-configuration-cookbook/ OpenvSwitch问答&#xff1a; http://openvsw…

mysql下载哪一代版本好_潮一代更好的设计

mysql下载哪一代版本好I think we can all agree that quarantined life has been strange. And while most of the day is comprised of the monotony of domestic life, I’ve been surprised at how much of my time is dominated by technology.我认为我们都可以同意隔离的…

预约清单ui设计_持续交付质量设计所需的UI清单

预约清单ui设计重点 (Top highlight)Over the past few months, my design team at StreetEasy has started experimenting in adding a “design buddy” check-in to the final stages of the design process.在过去的几个月中&#xff0c;我在StreetEasy的设计团队已开始尝试…

黑书上的DP例题

pagesectionnotitlesubmit1131.5.1例题1括号序列POJ11411161.5.1例题2棋盘分割POJ11911171.5.1例题3决斗Sicily18221171.5.1例题4“舞蹈家”怀特先生ACM-ICPC Live Archive1191.5.1例题5积木游戏http://202.120.80.191/problem.php?problemid12441231.5.2例题1方块消除http://…

静态创意和动态创意_我在22岁时学到的关于创意指导的知识

静态创意和动态创意During my last semester at college, I took a course titled “Collaborative Workshop”. The entire course focused on how to best collaborate within a team setting. We were placed into groups of 4 or 5. These were our “creative director” …

vim7.1在windows下的编码设置[转]

在gvm配置文件中&#xff1a; &#xff08;gvim安装目录下的_vimrc文件中&#xff09; """""""""""""""""""""""""""""&…

绝对编码和增量编码_用户体验设计师应该学习编码吗? 绝对

绝对编码和增量编码Even though I was trained as a graphic designer, I’ve never limited myself to that field exclusively. My particular interest in how things work didn’t allow me to stand still and as a young kid, I was already pulling apart all my toys t…

两个ID

在itpub上注册了ID googlgoracle &#xff0c;发过不少的求助帖子。 http://www.itpub.net/home.php?modspace&dothread&viewme 在CSDN 上ID:googlg,注册时间挺早的2008年&#xff0c;一直也没有弄过。 http://write.blog.csdn.net/postlist http://blog.csdn.net/goo…

完美主义怎么解决_相信我,你不要完美主义

完美主义怎么解决Perfectionism to UXers is like a badge of honour. We pride ourselves on the attention to detail and the drive to constantly push our work to the next level. When I asked some of my clients who share this sentiment about perfectionism, they …

MDK linker和debug的设置以及在RAM中调试

有误或者表述不清楚请指出&#xff0c;谢谢 硬件&#xff1a;TQ2440开发板、jlink V8 固件 软件&#xff1a;J-LINK ARM 4.08i、MDK4.20 先解释下MDK中三种linker之间的区别 设置集中在option linker选项卡 1.采用Target对话框中的ram和rom地址。采用此方式&#xff0c;…

FS_S5PC100 UBOOT-2011.12移植,支持DM9000

在uboot中已经支持了DM9000驱动代码在drivers/net/目录下的dm9000x.c dm9000x.h 修改include/configs/smdkc100.h 文件&#xff0c;注释掉SMC911X的支持&#xff0c;添加对DM9000的支持//#define CONFIG_SMC911X 1 /* we have a SMC9115 on-board *///#define…

为什么ui框架设计成单线程_评估UI设计的备忘单

为什么ui框架设计成单线程Whether you’re evaluating your design proposals or giving feedback to a colleague during a design critique or an informal conversation, you may find this actionable cheat sheet valuable. It’s quick to digest and its questions are …