editorial: http://discuss.codechef.com/questions/1123/resq-editorial
codechef RESQ - "arranging cup-cakes" solution: http://ideone.com/1v3r2t
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
int t, n, a, b, r;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
a=sqrt(n); b=r=0;
for(int i=a; i>0;) {
if(n%i!=0) i--;
else {
b=n/i; r=b-i; break;
}
}
printf("%d\n", r);
}
return 0;
}
codechef RESQ - "arranging cup-cakes"guidance:
i used 1st approach on the editorial. if you noticed, the question wants "almost" square cup-cakes, that means two divisors needs to be equal or "almost" equal(nearest possible numbers)
No comments:
Post a Comment