Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <string>
- #include <cctype>
- #include <stack>
- #include <queue>
- #include <list>
- #include <vector>
- #include <map>
- #include <set>
- #include <sstream>
- #include <stdlib.h>
- #include <cmath>
- #define FOR(i,A) for(typeof (A).begin() i = (A).begin() ; i != (A).end() ; i++)
- #define mp make_pair
- #define debug( x ) cout << #x << " = " << x << endl
- #define clr(v,x) memset( v, x , sizeof v )
- #define all(x) (x).begin() , (x).end()
- #define rall(x) (x).rbegin() , (x).rend()
- #define TAM 110
- using namespace std;
- typedef pair<int,int> ii ;
- typedef long long ll ;
- typedef long double ld ;
- typedef pair<int,ii> pii ;
- int sequenceLength(unsigned int n)
- {
- int length = 0;
- do
- {
- length+=(1+(n&1));
- n = ((1 + (2 * (n & 1))) * n + 1)>> 1;
- }while(n!=1);
- return length;
- }
- int main()
- {
- int maxI,max,n,m,t,i,c;
- scanf("%d %d",&n,&m);
- while(n||m)
- {
- maxI = -1;
- max = -1;
- if(n>m)
- {
- t = m;
- m = n;
- n = t;
- }
- for(i=n;i<=m;i++)
- {
- c = sequenceLength(i);
- if(c>max)
- {
- maxI=i;
- max = c;
- }
- }
- printf("Between %d and %d, %d generates the longest sequence of %d values.\n",n, m, maxI, max);
- scanf("%d %d",&n,&m);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement