Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*author : H. M. Tarek Ullah
- date : .0.02.15
- problem : 3n + 1 of UVA
- there is some mistake as i read the problem incorrectly . need to redo this program.
- */
- #include<iostream>
- #include<vector>
- using namespace std;
- bool odd_even(int num){
- if (num % 2 == 0)
- return true;
- else
- return false;
- }
- int main()
- {
- int starting_point = 0;
- int ending_point = 0;
- int copy_ending = 0;
- unsigned long int vec_size= 0;
- cin >> starting_point;
- cin >> ending_point;
- copy_ending = ending_point;
- vector<int> vec;
- while (ending_point != 1){
- if (odd_even(ending_point)){
- ending_point = ending_point / 2;
- if (ending_point < starting_point){
- vec.push_back(ending_point);
- }
- }
- else{
- ending_point = (ending_point * 3) + 1;
- if (ending_point < starting_point){
- vec.push_back(ending_point);
- }
- }
- }
- vec_size = vec.size() ;
- cout << starting_point<<" "<< copy_ending<<" "<< vec_size << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement