For every numbers, there are only numbers where the cows moo. (see below)
Therefore, we can just get the distance away is from the first by calculating , since we have to add for every grouping of .
Now it's just a matter of adding the corresponding first to the answer.
Implementation
Time Complexity:
Python
import syssys.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!