跳到主要内容

東京大学 情報理工学系研究科 創造情報学専攻 2015年2月実施 プログラミング

Author

itsuitsuki

Description

(1) The following function ff is a function often used as a simple random number generator.

f(n)={1if n<1,(161×f(n1)+2457)mod224otherwise.f(n) = \begin{cases} 1 & \text{if } n < 1, \\ (161 \times f(n-1) + 2457) \mod 2^{24} & \text{otherwise}. \end{cases}

where nn is a non-negative integer and modmod denotes a modulus operator (the remainder). Write a program that computes f(n)f(n) for given nn. Then print the value of f(100)f(100) by using this program.

(2) Write a program that counts the number of ii such that i<100i < 100 and f(i)f(i) is an even number.

(3) Write a program that counts the number of ii such that ii is an odd number, i<100i < 100, and f(i)f(i) is an even number.

(4) Write a program that prints the value of f(1000000)f(1000000).

(5) Write a program that computes the following function gg where nn is a non-negative integer:

g(n)={1if n<1,(1103515245×g(n1)+12345)mod226otherwise.g(n) = \begin{cases} 1 & \text{if } n < 1, \\ (1103515245 \times g(n-1) + 12345) \mod 2^{26} & \text{otherwise}. \end{cases}

Then run the program to print the values of g(2)g(2) and g(3)g(3).

(6) Write a program that computes the smallest positive integer kk such that g(n+k)=g(n)g(n + k) = g(n) for any non-negative integer nn.

(7) Write a program that computes the smallest positive integer kk such that h(n+k)=h(n)h(n+k) = h(n) for any non-negative integer nn. Write on the answer sheet why the program correctly computes kk. hh is a function defined as follows:

h(n)=g(n)mod210h(n) = g(n) \mod 2^{10}

题目描述

  1. 对非负整数 nn,定义常用作简单伪随机数发生器的递推函数

    f(n)={1,n<1,(161f(n1)+2457)mod224,n1.f(n)= \begin{cases} 1,&n<1,\\ (161f(n-1)+2457)\bmod2^{24},&n\ge1. \end{cases}

    其中 mod\bmod 表示取余。编写程序计算给定 nnf(n)f(n),并输出 f(100)f(100)

  2. 统计满足 i<100i<100f(i)f(i) 为偶数的 ii 的个数。

  3. 统计满足 i<100i<100ii 为奇数且 f(i)f(i) 为偶数的 ii 的个数。

  4. 编写程序输出 f(1000000)f(1000000)

  5. 对非负整数 nn,定义

    g(n)={1,n<1,(1103515245g(n1)+12345)mod226,n1.g(n)= \begin{cases} 1,&n<1,\\ (1103515245g(n-1)+12345)\bmod2^{26},&n\ge1. \end{cases}

    编写程序计算 gg,并运行输出 g(2)g(2)g(3)g(3)

  6. 编写程序求最小正整数 kk,使对任意非负整数 nn 均有 g(n+k)=g(n)g(n+k)=g(n)

  7. 定义

    h(n)=g(n)mod210.h(n)=g(n)\bmod2^{10}.

    编写程序求使任意非负整数 nn 均满足 h(n+k)=h(n)h(n+k)=h(n) 的最小正整数 kk,并在答题纸上说明程序为何能正确求得该 kk