首页 > 试题广场 >

Skew数

[编程题]Skew数
  • 热度指数:6498 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
在 skew binary表示中, 第 k 位的值xk表示xk*(2k+1-1)。 每个位上的可能数字是0 或 1,最后面一个非零位可以是2, 例如, 10120(skew) = 1*(25-1) + 0*(24-1) + 1*(23-1) + 2*(22-1) + 0*(21-1) = 31 + 0 + 7 + 6 + 0 = 44. 前十个skew数是 0、1、2、10、11、12、20、100、101以及102。

输入描述:
输入包含一行或多行,每行包含一个整数n。如果 n = 0 表示输入结束,否则n是一个skew数


输出描述:
可能有多组测试数据,对于每一个输入,
输出它的十进制表示。转换成十进制后的结果不超过 2^31-1 = 2147483647
示例1

输入

10120
200000000000000000000000000000
10
1000000000000000000000000000000
11
100
11111000001110000101101102000
0

输出

44
2147483646
3
2147483647
4
7
1041110737
头像 荞麦假面
发表于 2025-02-22 13:20:47
#include <cmath> #include <iostream> #include <string> using namespace std; int main() { string str; long long res; whi 展开全文
头像 T790T
发表于 2024-08-13 09:02:17
#include <bits/stdc++.h> using namespace std; int f(char c, int n) { int tmp = c-'0'; return tmp*(pow(2,n)-1); } int main() { stri 展开全文
头像 coder_bai
发表于 2023-03-20 02:41:50
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #include<algorithm> #include<iostream> #i 展开全文
头像 勋谦
发表于 2024-06-27 11:37:07
本来以为要用到高精度,因为数很大,结果long long也就过了 #include <iostream> #include <string> #include <algorithm> #include <math.h> using namespace 展开全文
头像 牛客381227913号
发表于 2024-03-28 23:09:03
while True: try: a = input() if a =="0": break l = len(a) s = 0 for i in range(l): 展开全文
头像 philos
发表于 2021-02-06 21:13:31
思路 题干无力吐槽,借用一下讨论中的更正: 在 skew binary 表示中,第 k 位的值 x[k] 表示 x[k]×(2^(k+1)-1)。每个位上的可能数字是 0 或 1,最后面一个非零位可以是 2,例如,10120(skew) = 1×(2^5-1) + 0×(2^4-1) + 1×(2^ 展开全文
头像 尤姆
发表于 2023-03-01 16:34:38
#include<cstdio> #include<cmath> using namespace std; int main(){ char num[100]; while (scanf("%s", &num) != EOF){ long long sum = 0; 展开全文
头像 Shawn698
发表于 2024-03-18 19:18:43
#include <cstdio> #include <string> #include <iostream> // 引入iostream以使用cin和cout #include "cmath" using namespace std; in 展开全文
头像 牛客7777779号
发表于 2023-03-03 10:39:42
用string存储大数 #include <cmath> #include <iostream> using namespace std; int main() { string n; while (cin >> n && n != "0") { 展开全文
头像 JXH001
发表于 2024-02-16 23:32:37
#include<iostream> #include<string> using namespace std; int D(char a, int n) { int c = 1; int temp = a - '0'; for (int i = 0; i < n 展开全文

问题信息

难度:
40条回答 7096浏览

热门推荐

通过挑战的用户

查看代码
Skew数