FunnyXEN
For a collection S(n)={1,2,…,2n}, we select some numbers from it. For a selection, if each selected number could not be divided exactly by any other number in this selection, we will call the selection good selection. Further, we call a good selection best selection if the selection has more elements than any other good selection from S(n). We define F(n) the number of elements in the best selection from S(n). For example, n=2, F(n)=2. From the collection {1,2,3,4}, we can make good selection just like {2,3} or {3,4}, but we can’t make any larger selection. So F(2) = 2.
Then we pay attention to XEN(n). For every S(n), there are always some numbers could not be selected to make up any best selection. For instance, when n=2, 1 is always could not be chosen. What’s more, for every S(n), there is a number k which satisfies that all the number, from 0 to k, are always could not be chosen. Now we let XEN(n)=k:
n=2, F(n)=2, XEN(2)=1;
n=4, F(n)=4, XEN(4)=1.
You should write a program to calculate the value of F(n) and XEN(n) with a given number n.
InputYour program is to read from standard input.
There are multiple cases. For each case, one integer n (1 ≤ n ≤ 10^7) in a line.OutputOutput two integers with one space between them in one line per case.Sample Input
2 4
Sample Output
2 1 4 1
对于任意正整数n,定义函数F(n)和XEN(n)。
对于集合S(n)={1,2,…,2n},我们从中选择一些数字。对于一个选择,如果每个选择的数字不能被这个选择中的任何其他数字精确地除,我们将称之为好选择。此外,我们称一个好的选择为最佳选择,如果这个选择比从S(n)中的任何其他好的选择有更多的元素。我们定义F(n)为S(n)中最佳选择的元素个数。例如,n=2,F(n)=2。从集合{1,2,3,4}中,我们可以做出像{2,3}或{3,4}一样好的选择,但是我们不能做出任何更大的选择。所以F(2)=2。
然后我们注意XEN(n)。对于每一个S(n),总是有一些数字不能被选择来组成任何最佳选择。例如,当n=2时,总是不能选择1。而且,对于每一个s(n),都有一个数k,它满足从0到k的所有数都是不能选择的。现在我们让XEN(n)=k:
n=2,F(n)=2,XEN(2)=1;
n=4,F(n)=4,XEN(4)=1。
你应该写一个程序来计算F(n)和XEN(n)的值。
1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 using namespace std; 5 int a[25],num[25]; 6 int n; 7 void init() 8 { 9 a[0]=0; 10 for(int i=1;i<20;i++) a[i]=2*a[i-1]+1; 11 num[1]=3; 12 for(int i=2;i<20;i++) num[i]=3*num[i-1]; 13 } 14 int main() 15 { 16 init(); 17 while(~scanf("%d",&n)&&n) 18 { 19 if(n==1) 20 { 21 printf("1 0\n"); 22 continue; 23 } 24 int m=0,x=1; 25 while(x<n) 26 { 27 m++; 28 x+=num[m]; 29 } 30 printf("%d %d\n",n,a[m]); 31 } 32 }