Translate

Views

Tuesday, July 25, 2023

Solution UVA: 350 - Pseudo-Random Numbers


 Problem  VerdictLangTimeBestRankSubmit Time
 | discuss350 - Pseudo-Random Numbers AcceptedC++110.0000.0008861 mins ago

Suggest: 

-Note a[0] should is (z*l+i)%m not l beacause:

"But be careful: the cycle might not begin with the seed!"


#include<bits/stdc++.h>
using namespace std;

int z, i, m, l, test;

int main(){
        ios::sync_with_stdio(0); cin.tie(0);
        while(cin >> z >> i >> m >> l && z && i && m && l){
                vector<int> a(1,(z*l+i)%m);
                do{
                        a.push_back((z*a.back()+i)%m);
                }while(a[0] != a.back());
                cout<<"Case "<<++test<<": "<<a.size()-1<<"\n";
        }
}

No comments: