Jason and Number
2014-04-13 17:38
405 查看
Problem Description
Given a number N, Jason will connect from the first prime number to the Nth prime to form a new number.Unfortunately, Jason has gone crazy, and he will repeat operation:
1、delete the number in the even position;
2、delete the number in the odd position.
Now, Jason wants to know what the last number is.
For example, if N is equal to 6, the new number is 23571113.
After deleting the number in even position, the new number is 2511
After deleting the number in odd position, the new number is 51
After deleting the number in even position, the new number is 5
Therefore, the last number is 5.
Input
The input will consist of a series of test cases, and each test case contains an integers N (N <= 20000).
Output
For each test case, output what the last number is.
Sample Input
6
Sample Output
5//解题报告:
在字符串长度为[1,3)时 输出第1个子符;
在字符串长度为[3,11)时 输出第3(1+2^1)个子符;
在字符串长度为[11,23)时
输出第11(3+2^3)个子符;
在字符串长度为[43,171)时
输出第43(11+2^5)个子符;
在字符串长度为[173,683)时
输出第171(43+2^7)个子符;
......;
//标程:
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<string.h>
#define Max 300010
using namespace std;
int prime[Max],cnt,vis[Max];
void prim()
{
cnt=0;
int i,j;
memset(vis,0,sizeof(vis));
for(i=2;;i++)
{
if(!vis[i])
{
prime[++cnt]=i;
if(cnt>20010) return;
for(j=2*i;j<=Max;j+=i)
vis[j]=1;
}
}
}
void tostr(string &str,int x)
{
while(x)
{
str+=(x%10+'0');
x/=10;
}
}
int main()
{
// freopen("a.txt","r",stdin);
prim();
int n,i,j;
int a[15];
a[0] = 1;
for(i = 1; i <= 10; i ++)
a[i] = a[i-1] + (1<<(2*i-1));
while(scanf("%d",&n)==1)
{
string str="";
for(i=n;i>=1;i--)
tostr(str,prime[i]);
reverse(str.begin(),str.end());
int len = str.size();
for(i = 0; i <= 10; i ++)
if(len < a[i]) break;
cout << *(str.begin() +a[i-1] - 1) <<endl;
}
return 0;
}
相关文章推荐
- java classloader原理深究
- 【HDOJ】1285 确定比赛名次
- ECJTU&&JXUST 13级新生友谊赛 题解
- Python入门教程-04 再论函数
- AngulatJS factory 使用Module(模块)组织依赖关系
- 关闭android系统自动更新
- 国内2大Git代码托管网站
- PropertySheet最简化例子
- 带着目标,努力前进!
- Java 将字节数组转化为16进制的多种方案
- Java 将字节数组转化为16进制的多种方案
- java程序流程控制之循环
- Java 将字节数组转化为16进制的多种方案
- 每天一句 linux命令
- Java 将字节数组转化为16进制的多种方案
- (转)[图]美国面试最难的25家公司 谷歌第8微软第16
- ACM Sdut 2158 Hello World!(数学题,排序) (山东省ACM第一届省赛C题)
- ArcGIS Engine 桌面工具参考技巧
- ad test
- django中form的CSS样式