Jason and Number

2024-05-30 20:08
文章标签 number jason

本文主要是介绍Jason and Number,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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;

这篇关于Jason and Number的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1016805

相关文章

usaco 1.2 Name That Number(数字字母转化)

巧妙的利用code[b[0]-'A'] 将字符ABC...Z转换为数字 需要注意的是重新开一个数组 c [ ] 存储字符串 应人为的在末尾附上 ‘ \ 0 ’ 详见代码: /*ID: who jayLANG: C++TASK: namenum*/#include<stdio.h>#include<string.h>int main(){FILE *fin = fopen (

题目1380:lucky number

题目1380:lucky number 时间限制:3 秒 内存限制:3 兆 特殊判题:否 提交:2839 解决:300 题目描述: 每个人有自己的lucky number,小A也一样。不过他的lucky number定义不一样。他认为一个序列中某些数出现的次数为n的话,都是他的lucky number。但是,现在这个序列很大,他无法快速找到所有lucky number。既然

Jenkins 通过 Version Number Plugin 自动生成和管理构建的版本号

步骤 1:安装 Version Number Plugin 登录 Jenkins 的管理界面。进入 “Manage Jenkins” -> “Manage Plugins”。在 “Available” 选项卡中搜索 “Version Number Plugin”。选中并安装插件,完成后可能需要重启 Jenkins。 步骤 2:配置版本号生成 打开项目配置页面。在下方找到 “Build Env

【Hdu】Minimum Inversion Number(逆序,线段树)

利用线段树在nlogn的时间复杂度内求一段数的逆序。 由于给的序列是由0 ~ n -1组成的,求出初始的逆序之后可以递推出移动之后的逆序数。 #include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const in

【JavaScript】基本数据类型与引用数据类型区别(及为什么String、Boolean、Number基本数据类型会有属性和方法?)

基本数据类型   JavaScript基本数据类型包括:undefined、null、number、boolean、string。基本数据类型是按值访问的,就是说我们可以操作保存在变量中的实际的值。 1)基本数据类型的值是不可变的 任何方法都无法改变一个基本类型的值,比如一个字符串: var name = "change";name.substr();//hangconsole.log

ORA-24067: exceeded maximum number of subscribers for queue ADMIN.SMS_MT_QUEUE

临时处理办法: delete from aq$_ss_MT_tab_D;delete from aq$_ss_MT_tab_g;delete from aq$_ss_MT_tab_h;delete from aq$_ss_MT_tab_i;delete from aq$_ss_MT_tab_p;delete from aq$_ss_MT_tab_s;delete from aq$

SQLSERVER排名函数RANK,DENSE_RANK,NTILE,ROW_NUMBER

SQL SERVER排名函数RANK,DENSE_RANK,NTILE,ROW_NUMBER 前言 本文意于用实例数据帮助理解SQL SERVER排名函数RANK,DENSE_RANK,NTILE,ROW_NUMBER。 准备工作 创建测试表:   ? 1 2 3 4 5 create table test( id int identity(1,1)

[LeetCode] 137. Single Number II

题:https://leetcode.com/problems/single-number-ii/ 题目大意 给定array,其中有一个元素只出现了1次,其他元素都出现了3次。 思路 求和 减去 (set(array)*3 - array)/2 作为答案。 class Solution {public int singleNumber(int[] nums) {Set<Long> se

Oracle - ORA-01789: Query block has incorrect number of result columns

一、原因     这个错误一般是在执行表之间的相加(union),相减(minus)等SQL语句时,两个个查询块具有不一致的结果列数所导致的。 二、方案     只要将两段SQL语句的列数调整为一致就可以解决。使用union时,要注意数据库字段的格式要一致,如varchar和nvarchar是不一样的。

Java Number 类和方法

一般地,当需要使用数字的时候,我们通常使用内置数据类型,如:byte、int、long、double 等。 实例 int a = 5000;float b = 13.65;byte c = 0x4a; 然而,在实际开发过程中,我们经常会遇到需要使用对象,而不是内置数据类型的情形。为了解决这个问题,Java 语言为每一个内置数据类型提供了对应的包装类。 所有的包装类(Integer、Lo