当前位置: 首页 > news >正文

题解:P11605 [PA 2016] 运算 / Jedynki

对于这道题,我们需要把最多 \(100\)\(1\) 组成一个式子,使得这个式子的结果为 \(k\)

由于出题人很穷,只给了 \(100\)\(1\)。那么,对于 \(k \le 100\) 的情况就直接用 \(k\)\(1\) 累加起来即可。

然后,我们来考虑 \(k\) 的值超过 \(100\) 该如何。

因为我们可以进行乘法操作,所以我们考虑分解因数。但是,又有一个困难摆在我们面前,对于大质数我们无法处理。但是我们将大质数减一,这个大质数就会成为一个合数。这是因为质数中只有 \(2\) 是偶数,其余都为奇数。

所以,用这个方法,我们可以把大质数、因数里含大质数的 \(k\) 处理出来。

由于增长量是 \(\log\) 级别的,所以在 \(10^9\) 范围之内一定能表示出所有数,所以不存在无解。

下面是代码环节:

#include<bits/stdc++.h>
#define int long long
using namespace std;
#define FIOBUFSIZ 1048576
#define NEGATIVE
struct freader {FILE*f;
#   ifdef ONLINE_JUDGEchar buf[FIOBUFSIZ], *p1, *p2;
#       define fgetc(f) (p1==p2&&(p2=(p1=buf)+fread(buf,1,FIOBUFSIZ,f),p1==p2)?EOF:*p1++)
#   endif
#   ifdef BOOLTRANSbool neof;
#       define NEOF(c) ((c)!=EOF||(neof=0))
#   else
#       define NEOF(c) ((c)!=EOF)
#   endif
#   ifdef NOTONLYDIGIT
#       define isdigit(c) ((c)>='0'&&(c)<='9')
#       define isnotdigit(c) ((c)<'0'||(c)>'9')
#   else
#       define isdigit(c) ((c)>='0')
#       define isnotdigit(c) ((c)<'0')
#   endiffreader(FILE*_f = stdin): f(_f) {
#       ifdef BOOLTRANSneof = 1;
#       endif
#       ifdef ONLINE_JUDGEsetvbuf(f, NULL, _IONBF, 0);p1 = p2 = buf;
#       endif}
#   ifdef NOTONLYDIGITvoid read(char&x) {for (x = fgetc(f); NEOF(x) && x <= ' '; x = fgetc(f));return;}void read(char*s) {for (*s = fgetc(f); NEOF(*s) && *s <= ' '; *s = fgetc(f));for (s++; NEOF(*s = fgetc(f)) && *s > ' '; s++);*s = '\0';return;}freader&operator>>(char*x) {
#           ifdef BOOLTRANSreturn *this ? read(x), *this : *this;
#           elsereturn read(x), *this;
#           endif}
#   endiftemplate<typename T>void read(T&x) {char c(fgetc(f));
#       ifdef NEGATIVEfor (; NEOF(c) && isnotdigit(c) && c != '-'; c = fgetc(f));if (c == '-')for (c = fgetc(f), x = 0; NEOF(c) && isdigit(c); c = fgetc(f))x = (x << 3) + (x << 1) - (c^'0');elsefor (x = 0; NEOF(c) && isdigit(c); c = fgetc(f))x = (x << 3) + (x << 1) + (c^'0');
#       elsefor (; NEOF(c) && isnotdigit(c); c = fgetc(f));for (x = 0; NEOF(c) && isdigit(c); c = fgetc(f))x = (x << 3) + (x << 1) + (c^'0');
#       endifreturn;}void ignore() {char c(fgetc(f));for (; NEOF(c) && c <= ' '; c = fgetc(f));for (; NEOF(c) && c > ' '; c = fgetc(f));return;}
#   if __cplusplus>=201103template<typename T, typename...Args>void read(T&x, Args&...args) {return read(x), read(args...);}
#   endiftemplate<typename T>freader&operator>>(T&x) {
#       ifdef BOOLTRANSreturn *this ? read(x), *this : *this;
#       elsereturn read(x), *this;
#       endif}
#   ifdef BOOLTRANSoperator bool() {return neof;}
#   endif
#   ifdef ONLINE_JUDGE
#       undef fgetc
#   endif
#   undef NEOF
#   undef isdigit
#   undef isnotdigit
} fin;
struct fwriter {FILE*f;
#   ifdef ONLINE_JUDGEchar buf[FIOBUFSIZ], *p1;
#       define fputc(c,f) (p1==buf+FIOBUFSIZ?fwrite(buf,1,FIOBUFSIZ,f),*(p1=buf)++=(c):*p1++=(c))
#   endiffwriter(FILE*_f = stdout): f(_f) {
#       ifdef ONLINE_JUDGEsetvbuf(f, NULL, _IONBF, 0);p1 = buf;
#       endif}~fwriter() {flush();}void flush() {
#       ifdef ONLINE_JUDGEfwrite(buf, 1, p1 - buf, f), p1 = buf;
#       elsefflush(f);
#       endifreturn;}void write(char c) {fputc(c, f);return;}void write(char*s) {for (; *s; s++)fputc(*s, f);return;}void write(const char*s) {for (; *s; s++)fputc(*s, f);return;}template<typename T>void write(T x) {if (!x) {fputc('0', f);return;}if (x < 0)fputc('-', f), x = -x;char s[41];int l(0);while (x)s[l++] = x % 10 ^ '0', x /= 10;while (l--)fputc(s[l], f);return;}
#   if __cplusplus>=201103template<typename T, typename...Args>void write(T x, Args...args) {return write(x), write(args...);}
#   endiftemplate<typename T>fwriter&operator<<(T x) {return write(x), *this;}
#   ifdef ONLINE_JUDGE
#       undef fputc
#   endif
} fout;
int t, k;
string ans;
void dfs(int u) {if (u == 1) {
//		ans += '1';fout << '1';return;}
//	ans += '(';fout << '(';for (int i = 2; i * i <= u; i ++) {if (u % i == 0) {dfs(i);
//			ans += '*';fout << '*';dfs(u / i);
//			ans += ')';fout << ')';return;}}
//	ans += '1';
//	ans += '+';fout << '1';fout << '+';dfs(u - 1);
//	ans += ')';fout << ')';
}
signed main() {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);fin >> t;while (t --) {fin >> k;if (k <= 100) {for (int i = 1; i < k; i ++) {fout << '1';fout << '+';} fout << '1';fout << '\n';continue;} dfs(k);
//		int len = ans.size();
//		for (int i = 0; i < len; i ++) {
//			fout << ans[i];
//		}fout << "\n";}return 0;
}
http://www.jsqmd.com/news/744242/

相关文章:

  • Gemini CLI Ralph扩展:AI驱动的自迭代开发循环实战指南
  • 从算盘到CPU:补码的诞生如何解决了计算机的‘减法难题’?一段被忽略的技术演进史
  • 六西格玛在国企有用吗? - 众智商学院官方
  • 从零到一:手把手教你用Qt Creator和C++为无人机地面站开发实时姿态显示界面
  • 三步掌握Umi-OCR:离线文字识别的终极解决方案
  • 被动展开球形机器人轨迹跟踪【附代码】
  • RemoteCC:基于WebSocket的本地网络远程终端控制方案
  • 题解:B3731 [信息与未来 2017] 房屋积水
  • Python多源数据融合卡顿?揭秘92%工程师忽略的3层内存泄漏陷阱及秒级修复方案
  • 题解:P11511 [ROIR 2017 Day 2] 大型直线对撞机
  • HS2-HF Patch:让Honey Select 2游戏体验焕然一新的神奇补丁
  • 当 AI 学会“三思后言”:安全护栏如何从源头掐灭偏见、幻觉与恶意攻击?
  • PrimerBank挖宝指南:如何快速找到小鼠/人基因已验证的qPCR引物(附结果解读)
  • 模型瘦身实战:利用TensorFlow Lite的量化与剪枝,将模型体积压缩80%
  • Python读取GE MRI序列报错“No valid SOP Class UID”?独家逆向解析厂商私有Tag映射表(仅限本期公开)
  • 南京黄金上门回收天花板!2026 无脑选 福正美黄金回收 - 福正美黄金回收
  • 基于Blob存储与React构建零运维加密货币仪表盘实战
  • 别再只看金叉死叉了!用通达信这个自定义指标,教你捕捉MACD背离的“黄金坑”与“风险区”
  • 5G手机里的紧急警报是怎么来的?手把手带你读懂SIB8系统消息
  • 2026 苏州黄金回收避坑指南:选福正美,不扣点不熔金 - 福正美黄金回收
  • 如何永久保存微信聊天记录:WeChatMsg本地免费工具完整指南
  • WeiboImageReverse:如何快速追溯微博图片原作者?终极免费解决方案指南
  • 柔性并联多维力传感器性能建模与解耦优化设计弹性薄板【附代码】
  • 企业级单目深度估计部署:Depth Anything V2 边缘计算优化实战方案
  • Fan Control:5分钟解决Windows电脑风扇噪音的终极免费方案
  • AI编程工具网络代理故障诊断:proxy-doctor五层模型解析
  • 外卖订单数据自动化采集终极指南:3步实现美团、饿了么、百度外卖订单整合
  • 题解:P8046 [COCI 2015/2016 #4] CHEWBACCA
  • 2026 西宁黄金回收优选:福正美线上线下双轨,全区域覆盖 - 福正美黄金回收
  • SubtitleOCR:基于异构计算优化的10倍速硬字幕提取技术解析