Advertisement
juanjo12x

UVA_371_Ackerman_Functions

Aug 13th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <cctype>
  7. #include <stack>
  8. #include <queue>
  9. #include <list>
  10. #include <vector>
  11. #include <map>
  12. #include <set>
  13. #include <sstream>
  14. #include <stdlib.h>
  15. #include <cmath>
  16. #define FOR(i,A) for(typeof (A).begin() i = (A).begin() ; i != (A).end() ; i++)
  17. #define mp make_pair
  18. #define debug( x ) cout << #x << " = " << x << endl
  19. #define clr(v,x) memset( v, x , sizeof v )
  20. #define all(x) (x).begin() , (x).end()
  21. #define rall(x) (x).rbegin() , (x).rend()
  22. #define TAM 110
  23.  
  24. using namespace std;
  25.  
  26. typedef pair<int,int> ii ;
  27. typedef long long ll ;
  28. typedef long double ld ;
  29. typedef pair<int,ii> pii ;
  30.  
  31.  
  32. int sequenceLength(unsigned int n)
  33. {
  34.     int length = 0;
  35.     do
  36.     {
  37.         length+=(1+(n&1));
  38.         n = ((1 + (2 * (n & 1))) *  n + 1)>> 1;
  39.     }while(n!=1);
  40.     return length;
  41. }
  42. int main()
  43. {
  44.     int maxI,max,n,m,t,i,c;
  45.     scanf("%d %d",&n,&m);
  46.     while(n||m)
  47.     {
  48.         maxI = -1;
  49.         max = -1;
  50.         if(n>m)
  51.         {
  52.             t = m;
  53.             m = n;
  54.             n = t;
  55.         }
  56.         for(i=n;i<=m;i++)
  57.         {
  58.             c = sequenceLength(i);
  59.             if(c>max)
  60.             {
  61.                 maxI=i;
  62.                 max = c;
  63.             }
  64.         }
  65.         printf("Between %d and %d, %d generates the longest sequence of %d values.\n",n, m, maxI, max);
  66.         scanf("%d %d",&n,&m);
  67.     }
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement