2013年3月百度之星A題

偽隨機數生成器

題目描述

?baidu熊最近在學習隨機算法,于是他決定自己做一個隨機數生成器。

這個隨機數生成器通過三個參數c, q, n作為種子, 然后它就可以通過以下方式生成偽隨機數序列:

m0=?c,

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

?

因為一些奇怪的原因,q 一定是奇數。現在du熊想知道對于一個給定的數 x ,是不是會出現在這個偽隨機數序列里面,如果存在的話,他還想知道最早是在哪里出現,即給定一個整數 x ,要求找出一個最小的整數 k 滿足?mk=?x.

輸入格式

輸入包含多組數據。

每個測試數據包含一行三個整數: 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.pswp.cn/news/274301.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274301.shtml
英文地址,請注明出處:http://en.pswp.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 …