当前位置:网站首页>L1-046 整除光棍 (20 分)
L1-046 整除光棍 (20 分)
2022-04-21 10:00:00 【WTXYL】
这里所谓的“光棍”,并不是指单身汪啦~ 说的是全部由1组成的数字,比如1、11、111、1111等。传说任何一个光棍都能被一个不以5结尾的奇数整除。比如,111111就可以被13整除。 现在,你的程序要读入一个整数x,这个整数一定是奇数并且不以5结尾。然后,经过计算,输出两个数字:第一个数字s,表示x乘以s是一个光棍,第二个数字n是这个光棍的位数。这样的解当然不是唯一的,题目要求你输出最小的解。
提示:一个显然的办法是逐渐增加光棍的位数,直到可以整除x为止。但难点在于,s可能是个非常大的数 —— 比如,程序输入31,那么就输出3584229390681和15,因为31乘以3584229390681的结果是111111111111111,一共15个1。
输入格式:
输入在一行中给出一个不以5结尾的正奇数x(<1000)。
输出格式:
在一行中输出相应的最小的s和n,其间以1个空格分隔。
输入样例:
31
输出样例:
3584229390681 15
注:
高精度乘法的变形
代码:
#include <iostream>
#include <vector>
using namespace std;
vector<int> mul(vector<int> & a, int b){
vector<int> c;
int t = -1;
while(t){
if(t == -1) t = 0;
for(int i = 0; i <= 9; i ++)
if((i * b + t) % 10 == 1){
a.push_back(i);
c.push_back(1);
t += i * b;
t /= 10;
break;
}
}
while(a.size() > 1 && a.back() == 0) a.pop_back();
return c;
}
int main(){
int b;
cin >> b;
vector<int> a;
vector<int> c = mul(a, b);
for(int i = a.size() - 1; i >= 0; i --)
cout << a[i];
cout << " " << c.size();
}
版权声明
本文为[WTXYL]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_46891900/article/details/124215137
边栏推荐
- [vi] summary
- The display problem of gltf model with transparent map
- 【愚公系列】2022年04月 微信小程序-项目篇(公交查询)-01周边站点
- CentOS下Docker中安装redis
- When uniapp encounters rolling penetration, a clever solution~
- 【手拉手 带你准备电赛】使用定时器中断更改PWM占空比
- Responsive layout to realize the static page of ghost blog home page
- [词性] 二十三、情态动词 2 [ have to ] [ ought to ] [ dare ] [ be able to ] [ needn‘t ]
- Ansible_02_playbook
- requires XXX>=YYY, but you‘ll have XXXX=ZZZ which is incompatible
猜你喜欢

比 Navicat 还要好用、功能更强大的工具!
![[pytorch] Monai vit network graphic analysis](/img/2d/7d81bb8281dec7e66c7420b18fb4b6.png)
[pytorch] Monai vit network graphic analysis
![[summary] 1296 - summarize 12 common mobile terminal H5 and hybrid development problems](/img/4d/c3216ead34b286bae58c030c3c4c00.jpg)
[summary] 1296 - summarize 12 common mobile terminal H5 and hybrid development problems
![[Excel函数] COUNT函数 | COUNTIF函数 | COUNTIFS函数](/img/fa/440ea44a9fa5a74fe4b8fc172dd493.png)
[Excel函数] COUNT函数 | COUNTIF函数 | COUNTIFS函数

【手拉手 带你准备电赛】单色块识别(基于openmv)

Exon bed file acquisition

wap图片

Yuanshu training dance room, cyberpunk cool style, waiting for you to dance

常用文本处理命令

Question brushing record (Niuke MySQL)
随机推荐
Daily question (2022-04-20) - the longest absolute path of the file
2022制冷与空调设备运行操作考试题模拟考试题库及答案
[Excel函数] COUNT函数 | COUNTIF函数 | COUNTIFS函数
【PyCharm Plugins】网上下载,来安装Translation插件
Yuanshu training dance room, cyberpunk cool style, waiting for you to dance
【DL-图像分类】
Responsive layout to realize the static page of ghost blog home page
【并发编程045】什么是伪共享内存顺序冲突?如何避免?
Grid layout -- grid
管道通信
【无标题】
ant a-table 表格数据同步
Jupyter notebook修改默认开启路径
Shell变量$#,$@,$0,$1,$2,${},##,%%使用解释以及好用的shell格式化工具
[DL image classification]
[hand in hand to prepare you for the video game] monochrome block recognition (based on openmv)
wap图片
SQL题集[(2)]
[hand in hand to prepare you for the electric game] use the timer interrupt to change the PWM duty cycle
You are using pip version 20.2.3; however, version 22.0.4 is available. You should consider