1 条题解
-
0
C++ :
#include<cstdio> #include<string> #include<cstring> #include<iostream> #include<istream> using namespace std; const int maxn = 100; struct bign { int len, s[maxn]; bign() { memset(s, 0, sizeof(s)); len = 1; } bign(int num) { *this = num; } bign(const char* num) { *this = num; } string str() const { string res = ""; for (int i = 0; i < len; i++) res = (char)(s[i]+'0') + res; if (res == "") res = "0"; return res; } bign operator = (const char* num) { len = strlen(num); for (int i = 0; i < len; i++) s[i] = num[len-i-1] - '0'; return *this; } bign operator = (int num) { char s[maxn]; sprintf(s, "%d", num); *this = s; return *this; } bign operator + (const bign& b) const { bign c; c.len = 0; for (int i = 0, g = 0; g || i < max(len, b.len); i++) { int x = g; if (i < len) x += s[i]; if (i < b.len) x+=b.s[i]; c.s[c.len++] = x % 10; g = x / 10; } return c; } bign operator += (const bign& b) { *this = *this + b; return *this; } bool operator < (const bign& b) const { if (len!=b.len) return len < b.len; for (int i = len-1; i >= 0; i--) if (s[i]!=b.s[i]) return s[i] < b.s[i]; return false; } bool operator > (const bign& b) const { return b < *this; } bool operator <= (const bign& b) const { return !(b < *this); } bool operator >= (const bign& b) const { return !(*this < b); } bool operator != (const bign& b) const { return b < *this || *this < b; } bool operator == (const bign& b) const { return !(b < *this) && !(*this < b); } }; istream& operator >> (istream &in, bign& x) { string s; in >> s; return in; } ostream& operator << (ostream &out, const bign& x) { out << x.str(); return out; } bign ans[210]; int main() { int n; ans[1] = 2; for (int i = 2; i <= 200; i++) { ans[i] = ans[i-1] + ans[i-1] + 2; // cout << ans[i] << endl; } while (cin >> n) cout << ans[n] << endl; return 0; }
Pascal :
var a,b:array[0..100] of integer; i,j,n:integer; begin read(n); b[100]:=1; for i:=1 to n do begin for j:=1 to 100 do b[j]:=b[j]*2; for j:=100 downto 1 do if b[j]>9 then begin b[j]:=b[j]-10; b[j-1]:=b[j-1]+1; end; for j:=1 to 100 do a[j]:=a[j]+b[j]; for j:=100 downto 1 do if a[j]>9 then begin a[j]:=a[j]-10; a[j-1]:=a[j-1]+1; end; end; j:=1; while a[j]=0 do j:=j+1; for i:=j to 100 do write(a[i]); end.
- 1
信息
- ID
- 256
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者