Official Analysis (C++)

For every 1515 numbers, there are only 88 numbers where the cows moo. (see below)

[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15][\underline{1}, \underline{2}, 3, \underline{4}, 5, 6, \underline{7}, \underline{8}, 9, 10, \underline{11}, 12, \underline{13}, \underline{14}, 15]

[16,17,18,19,20,21,22,23,24,25,26,27,28,29,30][\underline{16}, \underline{17}, 18, \underline{19}, 20, 21, \underline{22}, \underline{23}, 24, 25, \underline{26}, 27, \underline{28}, \underline{29}, 30]

Therefore, we can just get the distance away NN is from the first 88 by calculating N8×15\lfloor \frac{N}{8} \rfloor \times 15, since we have to add 1515 for every grouping of 1515.

Now it's just a matter of adding the corresponding first 88 to the answer.

Implementation

Time Complexity: O(1) \mathcal{O}(1)

Python

import sys
sys.stdin = open("moobuzz.in", "r")
sys.stdout = open("moobuzz.out", "w")
N = int(input())
# Lists the first 8.
# 14 is in the zeroth position since if were trying to find the
# eighth number, 8 % 8 = 0.

C++

#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
/*
* Lists the first 8.
* 14 is in the zeroth position since if were trying to find the

Java

import java.io.*;
import java.util.*;
public class MooBuzz {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("moobuzz.in"));
int N = Integer.parseInt(br.readLine());
br.close();
int[] first8 = {14, 1, 2, 4, 7, 8, 11, 13};

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!