Advertisement
Guest User

Picture Perfect

a guest
Feb 14th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. double x;
  7. int d1,d2,per;
  8. while (true) {
  9. cin >> x;
  10. if (x == 0) {
  11. break;
  12. }
  13. int n = (double) x;
  14. int a = sqrt(x);
  15. for (int i = 0; i < n; i++) {
  16. if (n%a+i == 0) {
  17. d1 = a+i;
  18. d2 = (int)n/d1;
  19. per = d1*2 + d2*2;
  20. }
  21. }
  22. cout << "Minimum perimeter is " << per << " with dimensions " << d1 << " x " << d2 << endl;
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement