#import <Foundation/Foundation.h>

NSString* toCol(int n)
{
  NSMutableString* s = [NSMutableString stringWithFormat:@"%C", 'A' + n%26];
  n /= 26;
  while (n > 0) {
    if (n <= 26) {
      [s insertString:[NSString stringWithFormat:@"%C", 'A' + n-1] atIndex:0];
      break;
    }
    n -= 1;
    [s insertString:[NSString stringWithFormat:@"%C", 'A' + n%26] atIndex:0];
    n /= 26;
  }
  return s;
}

int main()
{
  NSAutoreleasePool *pool = [NSAutoreleasePool new];
  int i;
  for (i=0; i<100; i++) {
    NSLog(@"%3d: %@", i+1, toCol(i));
  }
  [pool release];
  return 0;
}

