#include <math.h>

int prime(long int num){
	int i;
	int b=sqrt(num)+1;
	for (i = 1; i <= b; i++)
		if (num % i == 0)
			return 1;
	return 0;
}

#include <string.h>

size_t custom_strlen(const char* str) {
	return sizeof(str);
}
// TODO: Implement `power of` function
// int custom_pow(int base, int power);
long int custom_pow(int base, int power) {
	if (power == 0){
		return 1;
	}
	if (power > 0){
		long int a = base, i;
		for (i = 2; i <= power; i++)
			a = a*base;
		return a;
	}
	return 0;
}

#include <stdlib.h>
#include <stdio.h>

#define ERR_ARGS_COUNT (-1)
#define ERR_WRONG_FLG (-2)

#define TST_FOO_FIX     1
#define TST_FOO_IMPL    2
#define TST_MOD_IMPL    3


/* NOTE(stitaevskiy):
 * We use `atoi` function just for simplification and code reducing.
 * This function doesn't report conversation errors.
 * For safety program we recommend using `strtol` and its analogs.
 * (See `man atoi` and `man strtol` for more info).
 *
 * const char str_num[] = "1234";
 * char* end = NULL;
 * int val = (int) strtol(str_num, &end, 0);
 * if (end != '\0') {
 *     //ERROR
 * }
 *
 * */

int main(int argc, const char** argv) {
   	if (argc > 3) {
        	return ERR_ARGS_COUNT;
    	}
    	char *end = NULL;
    	int test_case = (int) strtol (argv[1], &end, 10);
	if (*end != '\0') {
		printf("Error: number of case is not found\n");
		return 0;	
	}
    	const char* data;
    	data = argv[2];
    	switch (test_case) {
        	case TST_FOO_FIX: {
            		size_t res = custom_strlen(data);
			printf("%zu\n", res);
            		break;
        	}
        	case TST_FOO_IMPL: {
            		if (argc != 4){
				printf("The number of input parameters is exceeded\n");
				return ERR_ARGS_COUNT;
			}
            		/* Comment to prevent `unused parameter` error
            		int base = atoi(data);
            		int pow =  atoi(argv[3]);
            		int res = custom_pow(base, pow);    // TODO: Implement me
            		printf("%i\n", res);
            		*/
			char *end1, *end2;
			end1=NULL;
			end2=NULL;	
			int base = (int) strtol (argv[2], &end1, 10);
			int pow = (int) strtol (argv[3], &end2, 10);
			if ((*end1 != '\n') && (*end2 != '\n')) {
				printf("DATA INPUT ERROR");
			}
			else {
				long int res = custom_pow(base,pow);
				printf("%ld\n", res);
			}
            		break;
        	}
        	case TST_MOD_IMPL: {
			if (argc != 3) {
				printf("The number of input parameters is exceeded\n");
			}
            		// Comment for prevent `unused variable` error
            		// int num = atoi(data);
			char *end1;
			end1 = NULL;
			int num = (int) strtol (argv[2], &end1,0);
			if (*end1 != '\n')
				printf("DATA INPUT ERROR");
			else {
				int pri = prime (num);
				printf("%d", pri);
			}
            		// TODO: Print to stdout `1` if `num` is prime number and `0` otherwise
            		// This function MUST be implemented in
            		// a separate C-module (not in `main` or `utils` module)
            		break;
        	}
        	default: {
            		return ERR_WRONG_FLG;
        	}
    	}
    	return 0;
}