USACO/Bronze

백준 5948 Bad Random Numbers (USACO December 2010 Bronze 2번)

ssam.. 2020. 4. 6. 21:35

문제 링크: https://www.acmicpc.net/problem/5948

 

5948번: Bad Random Numbers

Bessie is trying to generate random numbers. She stumbled upon an old reference to the 'middle square' method for making numbers that appear to be random. It works like this: Pick a starting four digit number (1 <= N <= 9999) Extract its middle two digits

www.acmicpc.net

같은 숫자를 또 방문할때까지 최종 몇개의 숫자를 방문하는지 세면 됨.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;
 
int n, v[10001], ans;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    cin >> n;
    while(!v[n]) {
        v[n] = 1;
        n = n / 100 % 10 * 10 + n / 10 % 10;
        n *= n;
        ans++;
    }
 
    cout << ans << '\n';
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter