0

I'm task to solve a problem in UVA and its problem 305 in particular well its easy to program it just brute forcing stuff. Part of the task is to find the big Oh of the program using frequency count

#include<stdio.h>


const int goodjoseph[] = {2,7,5,30,169,441,1872,7632,1740,93313,459901,1358657,2504881};
char k;

    int main(void){

        while(scanf("%u",&k) && k){

            printf("%u",k); 
            printf("%d\n",goodjoseph[k-1]);
    }

        return 0;
    }

from school we were taught basics of frequency count like

int x=1;      ---- 1
while ( x<=n) ---- n-x+2 = n+1
x = x + 1;    ---- n

Total = 2n+2 thus having big o(n);

can you help me find the frequency count for

while(scanf("%u",&k) && k){
Raphael
  • 72,336
  • 29
  • 179
  • 389
user90503
  • 101
  • 1
  • 5
    I don't understand what you're trying to do. The number of iterations of the loop depends entirely on user input: it runs as many times as the user tells it to run, modulo the undefined behaviour if the user asks for the 14th element of the fixed 13-element array. – David Richerby Apr 08 '16 at 16:19
  • Please get rid of the source code and replace it with ideas, pseudo code and arguments of correctness. See here and here for related meta discussions. – Raphael Apr 09 '16 at 09:16
  • Moving from source to pseudo code may actually lighten things up here. Hint: instead of reading input from the input stream, assume it's given in an array. – Raphael Apr 09 '16 at 09:17

0 Answers0