Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fermatova teorema
Author Message
ccmuha
Unregistered

 
Post: #1
Fermatova teorema
Ukoliko koga zanima da li je velika Fermatova teorema tacna

Code:
x^n+y^n=z^n

pri cemu su x, y, z, i n razliciti brojevi iz skupa N prirodnih brojeva,
bacite oko na slijedeci program koji to dokazuje bruteforce metodom Happy

Code:
#include<iostream.h>
#include<math.h>
int main ()
{
    long int x, y, z, n, d, l;
    for (n=3;n<=5;n++)
    {
        for (x=-72;x<=72;x++)
        {
            for (y=-72;y<=72;y++)
            {
               for (z=-72;z<=72;z++)
                {
                    if (x==y) goto ovdje;
                    if (x==z) goto ovdje;
                    if (y==z) goto ovdje;
                    if (n==z) goto ovdje;
                    if (n==y) goto ovdje;
                    if (n==x) goto ovdje;
                    
                    d=pow(z,n);
                    l=pow(x,n)+pow(y,n);
                    if (d==l)
                    {
                              cout<<"Ovo su te vrijednosti x, y, z, n: ";
                              cout<<"x je: "<<x<<" a y je: "<<y<<" i z je: "<<z<<" i n je: "<<n;
                              system("pause");}
                              }
                              }
                              ovdje:
                              cout<<".";
                              }
                              }
cout<<"\nNe postoji takav broj!";
cout<<"\n";
system ("pause");
}

P.S. Mrzim int i long int, uvijek naletim na neke belaje pa sam stavio granicu na 72^5 ako ko ima vremena neka mi pokaze kako bih to tacno napravio kao sto je zadano u teoremi Hmmm
28-09-2010 09:01 PM
Quote this message in a reply
r0tring Offline
Redoviti posjetitelj
**

Posts: 237
Joined: Apr 2009
Reputation: 11
Post: #2
RE: Fermatova teorema
Ova teorema tvrdi da za n>2 ne postoje cijeli brojevi x, y, z različiti od 0 takvi da je x^n + y^n = z^n.

Dakle, nisi sve dobro napisao, nigdje u teoremi ne piše da ovi brojevi moraju biti različiti... znači sva četiri broja mogu biti jednaka, ali logično ako su sva četiri jednaka, onda će sva četiri biti veća od 2, jer n mora biti veći od 2..

U tvom programu, varijable x,y,z i n ne moraju biti long, logično. i pokušaj što manje da koristiš "skokove" u programu (goto naredba).

Evo i ja sam nešto probao, sad nisam 100% siguran ni da je moje tačno, ali...

Code:
#include<iostream.h>
#include<math.h>

main ()
{
  long a, b, c;
  bool tacna = true;
    for (int n=3; n<=5; n++)
    {
        for (int x = -72; x <= 72; x++)
        {
            for (int y = -72; y <= 72; y++)
            {
               for (int z = -72; z <= 72; z++)
                {
                    if (x != 0 && y != 0 && z != 0) {    
                    a = pow(x, n);
                    b = pow(y, n);
                    c = pow(z, n);
                    
                    
                    if (a + b == c) {
                               cout << "Teorema nije tacna.\n";
                               cout<<x<<"^"<<n<<" + "<<y<<"^"<<n<<" != "<<z<<"^"<<n<<endl;
                               cout<<a<<" + "<<b<<" != "<<c<<endl;
                               cout<<a+b<<" != "<<c<<endl;
                               tacna = false;
                               break;
                             }
                     }
                 }
            }
        }
     }
    
if (tacna == true) {
cout<<"Teorema je ipak tacna!";
}

cout<<"\n";
system ("pause");
}

I dobra prilika da pitam stručnjake sa foruma, da li će u ovom slučaju (naravno ako se zadovolji uslov) break naredba izbaciti tok programa iz sve 4 for petlje ili samo iz zadnje? Hmmm
(This post was last modified: 28-09-2010 11:56 PM by r0tring.)
28-09-2010 11:52 PM
Find all posts by this user Quote this message in a reply
schmrz Offline
____
*

Posts: 567
Joined: Feb 2007
Post: #3
RE: Fermatova teorema
Nisam gledao ovo što se matematike tiče, dođoh samo da kažem da break izbacuje samo petlju u kojoj je napisan. :)

I have no drinking problems. I drink. Get drunk. Fall down. NO PROBLEM
Registered As Linux User #484215
Moj skromni blog
Savjet za buduće programere: ovdje
29-09-2010 12:52 PM
Find all posts by this user Quote this message in a reply
r0tring Offline
Redoviti posjetitelj
**

Posts: 237
Joined: Apr 2009
Reputation: 11
Post: #4
RE: Fermatova teorema
Kad si već došao zbog toga, mogao si reći i koja komanda izbacuje iz sve četiri pelje.. haha He he
29-09-2010 01:19 PM
Find all posts by this user Quote this message in a reply
ccmuha
Unregistered

 
Post: #5
RE: Fermatova teorema
Pa logicno je ako su a i c jednaki a b=0 onda ce teorema biti zadovoljena, prema tome ne smiju biti jednaki, a samo n mora biti vece od broja 2, dok ostale varijable ne moraju..
30-09-2010 07:30 PM
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)