mituri

[C++] specjlana trojka pitagorejska

Oct 1st, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. /*
  2. Project Euler("https://projecteuler.net/archives")
  3. Problem 9
  4.  
  5. A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
  6.  
  7. a^2 + b^2 = c^2
  8. For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
  9.  
  10. There exists exactly one Pythagorean triplet for which a + b + c = 1000.
  11. Find the product abc.
  12. */
  13.  
  14.  
  15. class triple{
  16. public:
  17. long long aa,bb,cc;
  18.  
  19. void setTriple(long long a, long long b, long long c){
  20. aa=a;
  21. bb=b;
  22. cc=c;
  23. }
  24. void show(){
  25. cout << aa << " " << bb << " " << cc << endl;
  26. }
  27. };
  28.  
  29. int main(){
  30.  
  31. const int powerRange = 600;
  32. long long a,b,c;
  33. int index = 0;
  34. vector <triple> tripleTab;
  35. triple tmp;
  36.  
  37. for(int i = 1; i < powerRange; i++){
  38. a = i*i;
  39. for(int j = i+1; j < powerRange; j++){
  40. b = j*j;
  41. for(int k = j+1; k < powerRange; k++){
  42. c = k*k;
  43. if( (a + b) == c){
  44. tmp.setTriple(i,j,k);
  45. tripleTab.push_back(tmp);
  46. if( (i+j+k) == 1000) cout << i*j*k << endl;
  47. index++;
  48. }
  49. }
  50. }
  51. }
  52.  
  53. for(int i = 0; i < tripleTab.size(); i++){
  54. // tripleTab[i].show();
  55. }
  56. system("PAUSE");
  57. }
Advertisement
Add Comment
Please, Sign In to add comment