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 }
FunnyXEN的更多相关文章
随机推荐
- 关于ajax 异步文件上传 node 文件后台接口
<body> <img src="" alt="" id="img"> <input type="f ...
- IdentityServer4 之 Resource Owner Password Credentials 其实有点尴尬
前言 接着IdentityServer4的授权模式继续聊,这篇来说说 Resource Owner Password Credentials授权模式,这种模式在实际应用场景中使用的并不多,只怪其太开放 ...
- PHP 获取重复数组中 第二多的元素
$target = ["重复项目", "repeat", "repeat", "重复", "重复项目" ...
- Haproxy-1.8.20 根据路径(URI)转发到后端不同集群
HAProxy根据不同的URI 转发到后端的服务器组 1 ) 实验内容说明: 1.1 ) 根据不同的URI 转发到后端的服务器组. /a /b 和其他 默认使用其他. 1.2 ) 使用IP介绍: ha ...
- 一道有趣的golang排错题
很久没写博客了,不得不说go语言爱好者周刊是个宝贝,本来想随便看看打发时间的,没想到一下子给了我久违的灵感. go语言爱好者周刊78期出了一道非常有意思的题目. 我们来看看题目.先给出如下的代码: p ...
- docker 创建数据卷容器
数据卷容器 --volumes-from 容器名/id 先起一个容器 docker run -it --name docker01 centos 然后同步 docker01 的数据卷 --volume ...
- linux线程数限制与zabbix监控
Linux最大线程数限制及当前线程数查询 最大线程数计算方式: n = total_memory/128k; Linux用户线程数限制而导致的程序异常为 java.lang.OutOfMemoryEr ...
- 【Linux】cron
每五分钟执行 */5 * * * * 每小时执行 0 * * * * 0 */1 * * * 效果相同 每天执行 0 0 * * * 每周执行 0 0 ...
- MAVEN编译NIFI源码
场景: 由于项目需求,需要借用NIFI进行二次开发,因此需要将NIFI源码进行修改,然后编译,办公环境无外网. 步骤: (1) 找一台可以上网(外网)的机器,安装java环境和maven环境,安装 ...
- ctfhub技能树—web前置技能—http协议—302跳转
开启靶机 打开环境,查看显示 点击Give me Flag后发生跳转 根据题目提示为HTTP临时重定向 简单记录一下HTTP临时重定向是什么 HTTP重定向:服务器无法处理浏览器发送过来的请求(req ...