#23772: C


liu76214@gmail.com (Andrew liu)

School : 新竹市立建功高級中學
ID : 92407
IP address : [111.243.122.123]
Last Login :
2021-08-15 15:26:39
c085. 00350 - Pseudo-Random Numbers -- UVa350 | From: [163.22.18.106] | Post Date : 2020-12-16 16:36

#include <stdio.h>

 

int main() {

    int z,l,i,m;

    int case_number = 1;

    while(scanf("%d%d%d%d", &z, &i, &m, &l) == 4){

        //  Z,L,I --> const

        if(z == 0 && l == 0 && i == 0 && m == 0)

            break;

        int abb = 0;

        int board[10000] = {0};

        while(board[l] == 0){

            abb++;

            board[l] = abb;

            l = (z * l + i) % m;

        }

        printf("Case %d: %d\n", case_number++, abb - board[l] + 1);

    }

    return 0;

}

 
ZeroJudge Forum