Codeforces Round #382 (Div. 2), problem: (D) Taxes Solution in C/C++

#include<stdio.h>
int isprime(int n);
int main(){
	int n;
	scanf("%d",&n);
	if(n%2==1){
		if(isprime(n)){
			printf("1");
		}else{
			printf("%d",3-isprime(n-2));
		}
	}else{
		printf("%d",1+(n>2));
	}
	return 0;
}
int isprime(int n){
	int i,j;
	for(i=2;i*i<=n;i++){
		if(n%i==0){
			return 0;
		}
	}
	return 1;
}
(Visited 74 times, 1 visits today)

About the Author:

Taniv Ashraf

Leave A Comment