Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //find xth lucas number
- //1, 3, 4, 7, 11, 18, 29 (same as fibonacci, but with 1 and 3 instead 1 and 1)
- #include <iostream> // cin cout
- using namespace std;
- int main()
- {
- bool check = true, prime; //za loop; za prime test
- unsigned long long int select; //iskano mesto v lucas sequence
- do{
- unsigned long long int first = 1, second = 3, temp; //seed za vrsto
- cout << "Vpisi zeljeno mesto: ";
- cin >> select; //vpises zeljeno mesto v lucas sequence
- for (int i = 0; i < select-2; i++) //isto kot pri fibonacci
- {
- temp = first + second;
- first = second;
- second = temp; //second iskana št
- }
- cout << "Na mestu " << select << " se nahaja stevilo " << second << "." << endl; //izpis
- cout << "To stevilo minus 1 (n-1) je " << second - 1 << "." << endl; //začetek prime testa
- if ((second - 1) % select == 0) //n je MOGOČE praštevilo če je nto mesto lucas sequenca (call that number p) - 1 deljivo z n
- prime = true;
- else
- prime = false;
- if (prime == true)
- cout << "Ker je " << second - 1 << " (" << second << " -1) deljivo z " << select << " je to stevilo mogoce prastevilo" << endl; // izpis če je myb praštevilo
- else
- cout << "Ker ni " << second - 1 << " (" << second << " -1) deljivo z " << select << " to stevilo zagotovo ni prastevilo" << endl; // izpis če ni
- cout << "1 za ponovitev, 0 za konec: ";
- cin >> check;
- } while (check == true);
- return 0; //note: int second overflowa pri okoli select = 90 (brez opozorila). 89 zadnje praštevilo ki ga lahko najde (vsaj rezultat tam pravilen), pri 97 rezultat že napačen
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement