第十届acm省赛-F-Binary to Prime

来源:互联网 发布:知乎 完颜亮 编辑:程序博客网 时间:2024/04/28 23:29

问题 F: Binary to Prime
时间限制: 1 Sec 内存限制: 128 MB
题目描述
To facilitate the analysis of a DNA sequence, a DNA sequence is represented by a binary number. The group of DNA-1 has discovered a great new way . There is a certain correlation between binary number and prime number. Instead of using the ordinary decadic numbers, they use prime base numbers. Numbers in this base are expressed as sequences of zeros and ones similarly to the binary numbers, but the weights of bits in the representation are not powers of two, but the elements of the primes ( 2, 3, 5, 7,… ).

For example 01101 , ie. 2+5+7=14

Herefore, it is necessary to convert the binary number to the sum of prime numbers

输入
The input consists of several instances, each of them consisting of a single line. Each line of the input contains a 01 string, length of not more than 150. The end of input is not marked in any special way.

输出
For each test case generate a single line containing a single integer , The sum of the primes.

样例输入

000010001111001

样例输出

3520

提示
每个二进制位对应一个素数位权,
代码:

#include<bits/stdc++.h>using namespace std;int a[200];void p()//初始化一个从小到大排序的素数数组;{    int i;    double q;    i=0;    for(int t=2;i<200;t++)    {        int fa=1;        for(int j=2;j<=sqrt(t);j++)        {            if(t%j==0)            {                fa=0;break;            }        }        if(fa)            a[i++]=t;    }}int main(){    int sum;    char s[200];    p();    while(~scanf("%s",s))    {        int l=strlen(s);        sum=0;        for(int i=0;i<l;i++)        {            if(s[l-i-1]=='1')//注意位权是从右往左增大的;            {                sum+=a[i];            }        }        printf("%d\n",sum);    }    return 0;}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 中文字字第9幕 yellow宇幕网在91 yellow国产字母幕91 183页中文 yellow中文字幕最新域名 超超人人中文字免幕费中文字幕 绝对中学生超卡哇视频 一频道中文字幕无线观看 一道中文不卡视频 中国中文字幕无线观看局域网 学妹开庖处疼流泪小说下载 学妹开庖处疼流泪视频网站 学生的母亲字幕中文翻译视频 中文不卡视频在线播放复古 学妹开庖处疼流泪视频 视频g 学妹开庖处疼流泪t 学妹开庖处疼流泪图新闻 学妹开庖处疼流泪漫画小说 学妹开庖处疼流泪高清 学妹开庖处疼流泪网站 039 年轻的老师3中文字中幕中国人 学妹开庖处疼流泪t小说 学妹开庖处疼流泪视频 视频中国 学妹开庖处疼流泪音频 中文字字视频人人 学妹开庖处疼流泪小说txt 学妹开庖处疼流泪视频 手机 视频字幕中文翻译 五姑娘中文视频版 小护土叫得太完整视频中文 上了瘾中文版视频 按摩院里的中国姑娘电影 五姑娘视频网搜 架起乳白腿一深一浅 9老师啪国线自产 老师你的水又多又甜视频 91国偷自产短视频网站 在卫生间里就做的视频 家庭毋HH伦s线播放中文字版 视频精二区 中文字 美国式 柰忌轧伦中文