codechef CHEFLUCK - "lucky lucky number" solution: http://ideone.com/pyXo1W
#include <iostream>#include <cstdio>
using namespace std;
int main() {
// your code goes here
int t;
long n;
scanf("%d", &t);
while(t--) {
scanf("%ld", &n);
if(n%7==0) printf("%ld\n", n);
else {
while(n>0) { n=n-4; if(n%7==0) { printf("%ld\n", n); break; } }
if(n%7!=0) printf("-1\n");
}
}
return 0;
}
codechef CHEFLUCK - "lucky lucky number" guidance:
to keep number smallest, maximize digit 4, which means maximize n's divisibility by 7.
No comments:
Post a Comment