Competitive/Collaborative Programming Class

ICPC Computer Programming Contest Prep

Problem Solving in Computer Science

Fall 2011 -- CSC 2700 Section 02

[Isaac's Home Page ]  [Mailing List ]  [Class Page ]  [Normal ]  

12/k/11847.cpp

/*
 * =====================================================================================
 *
 *       Filename:  11847.cpp
 *
 *    Description:  Problem 11847 - Cut the Silver Bar
 *
 *        Version:  1.0
 *        Created:  11/09/2011 07:06:33 PM
 *       Revision:  none
 *       Compiler:  g++
 *
 *         Author:  Andrew Stewart
 *        Company:  
 *
 * =====================================================================================
 */
#include <math.h>
#include <iostream>
using namespace std;
int f(int n) {
  if (n<2) return 0;
  else if (n<4) return 1;
  else if (n<8) return 2;
  else if (n<16) return 3;
  else if (n<32) return 4;
  else if (n<64) return 5;
  else if (n<128) return 6;
  else if (n<256) return 7;
  else if (n<512) return 8;
  else if (n<1024) return 9;
  else if (n<2048) return 10;
  else if (n<4096) return 11;
  else if (n<8192) return 12;
  else if (n<16384) return 13;
  else return 14;
}

int main() {
  int n;
  while (cin >> n && n) {
    cout << f(n) << endl;
  }
}

The statements and opinions included in these pages are those of only. Any statements and opinions included in these pages are not those of Louisiana State University or the LSU Board of Supervisors.
© 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Isaac Traxler