题意:

这里所谓的“光棍”,并不是指单身汪啦~ 说的是全部由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个空格分隔。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 20 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int main(){
string xx;
cin >> xx;
int len = xx.size();
int x = 0;
for(int i = 0; i < len; ++i){
x = x * 10 + xx[i] - '0';
}
int cnt = 0;
string s;
string ans;
while(1){
ans = "";
++cnt;
s += "1";
if(cnt < len) continue;
int sum = 0;
for(int i = 0; i < len; ++i){
sum = sum * 10 + 1;
}
int st = len;
if(x > sum){
sum = sum * 10 + 1;
++st;
}
if(cnt < st) continue;
while(st <= cnt){
int shang = sum / x;
ans += shang + '0';
sum %= x;
if(st == cnt) break;
++st;
sum = sum * 10 + 1;
}
if(sum == 0){
break;
}
}
cout << ans << " " << cnt << endl;
return 0;
}

  

最新文章

  1. WPF -Enum的三种绑定方法
  2. &lt;input type=&quot;file&quot; id=&quot;camera&quot; multiple=&quot;multiple&quot; capture=&quot;camera&quot; accept=&quot;image/*&quot;&gt; 上传图片,手机调用相册和摄像头
  3. nginx服务器在IE下载时,apk,ipa文件变成zip的解决方法
  4. Windows Azure上搭建SSTP VPN
  5. 用jstack工具分析java程序
  6. Servlet &amp; JSP - Filter
  7. js模拟触发事件
  8. 利用php获取图片完整Exif信息类 获取图片详细完整信息类
  9. sphinx 简介以及安装 以及php拓展开启
  10. CentOS 7 之找回失落的ifconfig
  11. Hadoop集群日常运维
  12. java读取property文件
  13. 河南多校大一训练赛 G 硬币
  14. yaf插件类的使用
  15. cannot update the cursor rep,since it is read-only
  16. 自动化运维工具Ansible介绍
  17. Python语言——基础01-环境安装、注释、变量
  18. ForkJoinPool 源码
  19. Java Integer 与 int 深刻理解
  20. ARM中几个典型的汇编指令解析

热门文章

  1. HD Tune检查硬盘各参数的含义
  2. [ DLPytorch ] 注意力机制&amp;机器翻译
  3. 转载--centos7.4安装docker
  4. Redis学习笔记(一)配置文件参数说明
  5. hbase单机版安装
  6. Java基础知识笔记第十章:输入输出流
  7. Caffe2 用户手册概览(Caffe2 Tutorials Overview)[1]
  8. Flex 学习笔记
  9. 3_03_MSSQL课程_Ado.Net_数据导入
  10. 题解 P4949 【最短距离】