#import // 2 4 3 output is 27 @interface ModPow : NSObject + (NSInteger)xsqrmodpow:(NSInteger )b x:(NSInteger)X m:(NSInteger)M; @end @implementation ModPow + (NSInteger)xsqrmodpow:(NSInteger )b x:(NSInteger)X m:(NSInteger)M { uint64 B, D; B = b; B %= M; D = 1; if ((X & 1) == 1) { D = B; } while(X > 1) { X >>= 1; B = (B * B) % M; if ((X & 1) == 1) { D = (D * B) % M; } } return (uint32)D; } @end int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... char input[5000000]; scanf("%[^\n]%*c",input); NSString *inputString = [NSString stringWithCString:input encoding:NSUTF8StringEncoding]; NSArray *inputArray = [inputString componentsSeparatedByString:@" "]; NSInteger a = [inputArray.firstObject integerValue]; NSInteger b = [inputArray[1] integerValue]; NSInteger t = [inputArray[2] integerValue]; long result = 1; long bb = 0.5*(a+b); long e = t; long m = pow(10, 9) + 7; result = [ModPow xsqrmodpow:bb x:e m:m]; printf("%ld", result); } return 0; }