Skip to content

Instantly share code, notes, and snippets.

@godtaehee
Created January 17, 2019 00:30
Show Gist options
  • Save godtaehee/0a7718da7e2f82e1c4c4d59e2b5b452e to your computer and use it in GitHub Desktop.
Save godtaehee/0a7718da7e2f82e1c4c4d59e2b5b452e to your computer and use it in GitHub Desktop.
C
#include <stdio.h>
int main(){
int N;
int x, y;
int min = 1000;
int correct = 0;
scanf("%d", &N);
if(N < 3 || N > 5000){
printf("-1");
}
else if(N % 5 == 0 && N % 3 == 0){
printf("%d", N/5);
}
else if(N % 5 == 0 && N % 3 != 0){
printf("%d", N/5);
}
else{
x = N/5;
y = N/3;
for(int i = 0; i <= x; i++){
for(int j = 0; j <= y; j++){
if(N == 5 * i + 3 * j){
correct = 1;
if(min >= i + j){
min = i + j;
}
}
}
}
if(correct == 1)
printf("%d", min);
else
printf("-1");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment