Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
99864 陈志轩 拆分自然数 C++ 通过 100 41 MS 264 KB 924 2023-08-24 09:30:02

Tests(5/5):


#include<bits/stdc++.h> #define int long long using namespace std; namespace Fast{ inline int fr(){ int x = 0,f = 1; char c = getchar(); while (c < '0' || c > '9'){ if (c == '-'){ f = -1; } c = getchar(); } while (c >= '0' && c <= '9'){ x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } inline void fw(int x){ if (x < 0){ x = -x; putchar('-'); } if (x > 9){ fw(x / 10); } putchar(x % 10 + 48); } } using namespace Fast; int sum,ret[114514],n; void dfs(int x,int lstnum,int len){ if (x == 0){ if (ret[1] == n){ return ; } cout<<n<<'='<<ret[1]; for (int i = 2;i <= len;i++){ cout<<'+'<<ret[i]; } sum++; puts(""); return ; } for (int i = lstnum;i <= x;i++){ ret[len + 1] = i; dfs(x - i,i,len + 1); } } signed main(){ n = fr(); dfs(n,1,0); fw(sum); return 0; }


测评信息: