Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. using namespace std;
  2. #include<iostream>
  3.  
  4. int main() {
  5. int T;
  6. cin >> T;
  7.  
  8. while (T >= 1) {
  9. int n, flag;
  10. cin >> n;
  11. int z = n;
  12.  
  13. if(n%5==0){
  14. for(int r=1;r<=n;r++){
  15. cout<<"3";
  16. }cout<<"n";
  17. }
  18.  
  19. else if(n%5!=0){
  20. for (int i = 3; i <= n; i += 3) {
  21. if ((z - i) % 5 == 0) {
  22. flag = i;
  23. break;
  24. }
  25. }
  26.  
  27. if (flag == 0|| (n-flag)%5!=0) {
  28. cout << "-1"<<"n";
  29. }
  30.  
  31. else {
  32. for (int x = 1; x <= flag; x++) {
  33. cout << "5";
  34. }
  35. for (int y = 1; y <= (n - flag); y++) {
  36. cout << "3";
  37. }
  38. cout<<"n";
  39. }
  40. }
  41. T--;
  42. }
  43. }
  44.  
  45. 3 * f + 5 * t = n
  46.  
  47. f = n/3 - 5/3 * t
  48.  
  49. n % 3 == (5 * t) % 3
  50.  
  51. switch (n % 5):
  52. case 0: t = 0;
  53. case 1: t = 2;
  54. case 2: t = 1;
  55.  
  56. if (5 * t <= n):
  57. print "5".repeat(n - 5 * t) + "3".repeat(5 * t)
  58. else
  59. print "-1"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement