Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Project Euler("https://projecteuler.net/archives")
- Problem 9
- A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
- a^2 + b^2 = c^2
- For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
- There exists exactly one Pythagorean triplet for which a + b + c = 1000.
- Find the product abc.
- */
- class triple{
- public:
- long long aa,bb,cc;
- void setTriple(long long a, long long b, long long c){
- aa=a;
- bb=b;
- cc=c;
- }
- void show(){
- cout << aa << " " << bb << " " << cc << endl;
- }
- };
- int main(){
- const int powerRange = 600;
- long long a,b,c;
- int index = 0;
- vector <triple> tripleTab;
- triple tmp;
- for(int i = 1; i < powerRange; i++){
- a = i*i;
- for(int j = i+1; j < powerRange; j++){
- b = j*j;
- for(int k = j+1; k < powerRange; k++){
- c = k*k;
- if( (a + b) == c){
- tmp.setTriple(i,j,k);
- tripleTab.push_back(tmp);
- if( (i+j+k) == 1000) cout << i*j*k << endl;
- index++;
- }
- }
- }
- }
- for(int i = 0; i < tripleTab.size(); i++){
- // tripleTab[i].show();
- }
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment