链接:

https://www.acwing.com/problem/content/204/

题意:

8是中国的幸运数字,如果一个数字的每一位都由8构成则该数字被称作是幸运数字。

现在给定一个正整数L,请问至少多少个8连在一起组成的正整数(即最小幸运数字)是L的倍数。

思路:

求出式子8(10^x-1)/9为8组成的正整数.

另其为G, 有L|G, 两边同乘9,9
L | 8(10^x-1),为了去掉右边的8, 令右边为变为原来的1/8, 左边变为原来的gcd(L, 8)倍.

令d = gcd(8, L), 9
L/d 与 8/L互质, 因为9L/d | 8/d(10^x-1), 所以有9L/d | (10^x-1).

剩下就是同余, 10^x = 1 (mod 9
L/d)假装是同余符号.

根据欧拉定理, x为fai(9*L/d) 的约数.枚举再暴力判断.

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL; LL n; LL Pow(LL a, LL b, LL mod)
{
LL res = 1;
while (b)
{
if (b&1)
res = (res*a)%mod;
a = (a*a)%mod;
b >>= 1;
}
return res;
} LL Euler(LL x)
{
LL res = x;
for (int i = 2;i <= x;i++)
{
if (x%i == 0)
{
while (x % i == 0)
x /= i;
res = res/i*(i - 1);
}
}
if (x > 1)
res = res/x*(x-1);
return res;
} LL Solve(int cnt, LL mod)
{
LL res = 1e18;
for (LL i = 1;i*i <= cnt;i++)
{
if (cnt%i == 0)
{
// cout << i << endl;
if (Pow(10, i, mod) == 1)
res = min(res, i);
if (Pow(10, cnt/i, mod) == 1)
res = min(res, cnt/i);
}
}
if (res == 1e18)
return 0;
return res;
} int main()
{
int cnt = 0;
while (~scanf("%lld", &n) && n)
{
LL eul = Euler((9LL*n)/__gcd(8LL, n*9));
// cout << eul << endl;
LL res = Solve(eul, (9LL*n)/__gcd(8LL, n*9));
printf("Case %d: %lld\n", ++cnt, res);
} return 0;
}

最新文章

  1. Java多线程系列--“JUC线程池”03之 线程池原理(二)
  2. Kafka在Centos6.4中的集群搭建
  3. org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
  4. bootstrap菜单完美解决---原创
  5. Flash Air 打包安卓 ane
  6. Ant学习---第二节:Ant添加文件夹和文件夹集的使用
  7. VxWorks 6.9 内核编程指导之读书笔记 -- 多任务(二)
  8. javascript函数的4种调用方式
  9. motan源码分析六:客户端与服务器的通信层分析
  10. Windbg调试命令详解(1)
  11. mysql排序
  12. docker在CentOS7下部署指南
  13. 新年Flag,零基础程序媛编程学习计划(持续更新ing)~~
  14. python第一天,简单输出及基本运算符
  15. TensorRT caffemodel serialize
  16. hive orc update
  17. (转)CentOS7下yum安装mysql配置多实例
  18. JS截图(html2canvas)
  19. 《Two Dozen Short Lessons in Haskell》(二十二)递归
  20. oracle 查看主外键约束

热门文章

  1. svn服务器端的更新操作
  2. Postfix to Prefix Conversion &amp; Prefix to Postfix Conversion
  3. github与pycharm
  4. Tomcat: has been normalized to [null] which is not valid
  5. 项目四:Java秒杀系统方案优化-高性能高并发实战
  6. MHA原理及搭建
  7. vue 模拟测试数据构建
  8. Selenium IDE for firefox
  9. O035、Nova Suspend / Rescue 操作详解
  10. webpack抽取CSS文件与CSSTreeShaking