第十届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;}
- 第十届acm省赛-F-Binary to Prime
- 第十届ACM省赛-F Binary to Prime
- 第十届河南acm省赛F: Binary to Prime
- F Binary to Prime 河南第十届ACM真题 【模拟】
- 河南省第十届ACM省赛题目:问题 F: Binary to Prime
- 河南省第十届ACM省赛题解 F Binary to Prime
- 2017年河南省ACM省赛 Problem F: Binary to Prime
- 问题 F: Binary to Prime
- 省赛 Binary to Prime
- Full Binary Tree 2014 SD第五届ACM大学生程序设计竞赛 F
- 河南第十届ACM省赛-E-八纵八横
- 河南第十届ACM省赛-D-年终奖金
- 第十届ACM省赛-A 谍报分析
- 山东省第二届ACM省赛 F题 Manhattan 解题报告
- 山东省第一届ACM省赛 F SDUT 2156 Fairy tale
- NYOJ1253 第七届acm省赛 F Turing equation
- 山东省第八届ACM省赛 F 题(quadratic equation)
- 山东省第八届ACM省赛F.quadratic equation
- 《Effective C++》(二)
- spring事务管理
- 2、一个简单的Linux下的socket程序
- dell xps13如何快速锁定Fn键
- POJ
- 第十届acm省赛-F-Binary to Prime
- 做个简单的公告栏
- LeetCode 35. Search Insert Position
- Openwrt WIFI探针开发【二】
- 3、一个简单的Windows下的socket程序
- 得到APP之订阅专栏《5分钟商学院》和《薛兆丰的北大经济学课》目录
- 4、WSAStartup()函数以及DLL的加载
- 设置python的默认编码为utf8
- C#事件