Jason and Number
来源:互联网 发布:地面互动投影软件 编辑:程序博客网 时间:2024/04/29 14:53
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
Sample Output
#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;
}
- Jason and Number
- Jason
- jason jason jason
- Number literal and representation
- Types and Number Representation
- letter and number
- Fox and Number Game
- XOR and Favorite Number
- Soldier and Number Game
- Single number and Single Number IIt
- Fixed-Point Number and Floating-Point Number
- sdut 2609 A-Number and B-Number
- A Cubic number and A Cubic Number
- A Cubic number and A Cubic Number
- **A Cubic number and A Cubic Number**
- A Cubic number and A Cubic Number
- A Cubic number and A Cubic Number
- A Cubic number and A Cubic Number
- 给定一篇学术论文,怎样深入浅出地向别人做好oral presentation
- 递归删除所有SVN文件
- Visual C++ 基础数据类型的转换
- 循环队列
- 网站上线
- Jason and Number
- POJ 3094
- (转)[图]美国面试最难的25家公司 谷歌第8微软第16
- django中form的CSS样式
- 管理之转变自己的角色
- 关闭android系统自动更新
- unicode到utf-8的转换
- 嵌入式开发环境配置
- ECJTU&&JXUST 13级新生友谊赛 题解