The Luckiest number POJ - 3696 (欧拉函数)

HALCON实战:用两个工业相机实现无缝大视野拼接(附完整代码与避坑指南) 本文详细介绍了使用HALCON软件实现双工业相机图像无缝拼接的完整解决方案,涵盖硬件配置、相机标定、坐标系转换和图像拼接等关键步骤。通过高精度标定和矩阵变换技术,可构建大视野检测系统,适用于液晶面板、PCB等工业检测场景,显著提升检测效率和精度。 阅读详情

Chinese people think of ‘8’ as the lucky digit. Bob also likes digit ‘8’. Moreover, Bob has his own lucky number L. Now he wants to construct his luckiest number which is the minimum among all positive integers that are a multiple of L and consist of only digit ‘8’.

Input
The input consists of multiple test cases. Each test case contains exactly one line containing L(1 ≤ L ≤ 2,000,000,000).

The last test case is followed by a line containing a zero.

Output
For each test case, print a line containing the test case number( beginning with 1) followed by a integer which is the length of Bob’s luckiest number. If Bob can’t construct his luckiest number, print a zero.

Sample Input
8
11
16
0
Sample Output
Case 1: 1
Case 2: 2
Case 3: 0
又是欧拉函数 。。。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll gcd(ll x,ll y)
{
    return x%y?gcd(y,x%y):y;
}
ll euler(ll n)
{
    ll res=n,a=n;
    for(int i=2;i*i<a;i++)
        if(a%i==0)
    {
        res=res/i*(i-1);
        while(a%i==0)
        a/=i;
    }
    if(a>1)
        res=res/a*(a-1);
    return res;
}
long long multi(long long a,long long b,long long mod) {
    long long ret=0;
    while(b) {
        if(b&1)
            ret=(ret+a)%mod;
        a=(a<<1)%mod;
        b=b>>1;
    }
    return ret;
}
long long poww(long long a,long long b,long long mod) {
    long long ret=1;
    while(b) {
        if(b&1)
            ret=multi(ret,a,mod);  //直接相乘的话可能会溢出
        a=multi(a,a,mod);
        b=b>>1;
    }
    return ret;
}
int main()
{
    ll n;
    int count=1;
    for(;;)
    {
        scanf("%lld",&n);
        if(n==0)break;
        ll d=gcd(8,n);
        n=n*9/d;
        if(gcd(10,n)!=1)
            cout<<"Case "<<count++<<": 0"<<endl;
        else
        {
            ll phi=euler(n);
            ll up=sqrt((double)phi);
            ll ans=phi;
            bool sign=false;
            for(int i=1;i<=up;i++)
                if(phi%i==0&&poww(10,(ll)i,n)==1)
                {
                    ans=i;
                    sign=true;
                    break;
                }
            if(!sign)
            for(int i=up;i>=2;i--)
                if(phi%i==0&&poww(10,phi/i,n)==1)
                {
                    ans=phi/i;
                    break;
                }
            cout<<"Case "<<count++<<": "<<ans<<endl;
        }
    }

    return 0;
}
LangGraph实战:用Plan-and-Execute模式5步搭建智能问答机器人(附Tavily搜索集成) 本文详细介绍了如何利用LangGraph的Plan-and-Execute模式,通过规划、执行、动态调整三个核心阶段,构建一个能够处理复杂多步骤问题的智能问答机器人。文章提供了从环境配置、状态管理到核心节点(规划、执行、重新规划)实现的完整实战指南,并集成了Tavily搜索工具,展示了如何将智能任务规划应用于实际信息查询场景。 阅读详情

相关推荐

单机多环境部署apollo 2.3.0

理解apollo的整体架构后,对比nacos配置中心功能点,其设计的复杂度以及完整度相较nacos而言更为丰富 对于不同的环境,例如 FAT, PRO 在部署时进程已经完全物理隔离,并且每个环境config/adminservice依赖的数据也完全物理隔离(连接不同的db),在数据隔离与安全方面做的很完善,但同时也提升了架构的复杂度 而 portal 可以管理多个环境,单节点部署虽然有单点问题,但并不会影响业务从configservice读取配置, 挂掉只要重启就可以,只是在

Life is a starting point everywhere 1305

poj-3696(欧拉定理+推导)

DescriptionChinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own lucky number L. Now he wants to construct his luckiest number which is the minimum among ...

wust_cyl的博客 680

Aras Innovator生命周期图实战:从配置到权限管理的全流程解析

本文详细解析了Aras Innovator生命周期图的全流程配置与权限管理,从基础概念到实战应用,涵盖状态设置、路径配置、权限控制等核心功能。通过实际案例和代码示例,帮助用户掌握如何高效管理数据生命周期,提升业务流程的规范性和效率。

ee345的博客 177

POJ - 3696 The Luckiest number 【欧拉函数】

Description Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own lucky numberL. Now he wants to construct his luckiest number which is the minimum amo...

一定要站在自己热爱的生活里闪闪发光 3万+

win11系统ping另一台电脑上VMware虚拟机的IP

我是用了两台电脑,所以刚才遇到一个问题就是两台电脑的IP 在同一局域网内ping不通。于是就找了很多资料,经过坚强的绝望后终于解决了。 下开始解决问题: VMWare提供了三种工作模式:bridged(桥接模式)、NAT(网络地址转换模式)和host-only(主机模式)。 1. bridged(桥接模式)   在这种模式下,VMWare虚拟出来的操作系统就像是局域网中的一台独立主机,它可以访问网内任何一台机器。在桥接模式下,你需要手工为虚拟系统配置IP地址、子网掩码,而且还要和宿主机器处于同一网段,这样虚

qq_42817360的博客 3240

【WRF安装(2025)】服务器移植 WRF 安装环境

【WRF安装(2025)】服务器移植 WRF 安装环境

WW、forever的博客 110

POJ - 3696 The Luckiest number(欧拉定理)

POJ - 3696 The Luckiest number #include<cstdio> #include<algorithm> using namespace std; typedef long long LL; int gcd(int a,int b){return b?gcd(b,a%b):a;} LL mul(LL a,LL b,LL p) { LL res=0,t=a%p; for(;b;b>>=1) { if(b&1) re

00后的博客 248

Puchem化合物数据批量抓取采集_宝典_教程_Python爬虫

本文共计6500字,导出到PDF达42页(含代码)。从0教你如何抓取Pubchem化合物数据。 1、 Pubchem介绍 ​ Pubchem是美国国立卫生研究院(NIH)的开放式化学数据库,自2004年推出以来,pubchem已成为科学家、学生和公众的重要化学信息资源。其专门针对化学结构搜索,是网络药理学研究经常用到的数据库之一,不仅使用方便而且免费。 ​ PubChem主要包含小分子,但也包含较大的分子,例如核苷酸,碳水化合物,脂质,肽和化学修饰的大分子。收集有关化学结构,标识符,化学和物理性..

qq_34843422的博客 6078

poj3696(欧拉,快速幂,快速乘,gcd)

题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> #include<string> #include<vector> #include<map> #include<queue> #include<stack> #include&lt

weixin_45714726的博客 192

【目标跟踪】多目标跟踪的评价工具motmetrics怎么使用?

多目标跟踪,通过motmetrics测试评价对应的视频。

聿默的博客 5369

【数字IC设计】芯片设计中的RDC

在芯片设计中,RDC是的缩写,类似于CDC(clock domain crossing),由于现在SOC芯片是有很多ECUs组成,为了使整个系统能够快速从复位中恢复, 用户希望SOC里面每个ECU模块都可以有自己独立的异步复位信号,这样可以在出问题的时候只复位有错误逻辑的模块,而使其它模块保持正常工作。

qq_40268672的博客 2203

Just Skip The Problem

Just Skip The Problem Problem Description Y_UME has just found a number x in his right pocket. The number is a non-negative integer ranging from 0 to 2n−1 inclusively. You want to know the exact value...

weixin_44941429的博客 382

三、参考比较法之城市建成区提取——提取

在正式开始提取之前,还是要继续啰嗦一下,其实基于夜间灯光数据建成区提取,可以分为好几个层次,基于县一级、市一级、省一级,很多论文的做法都是以市一级为准,也就是统计好市一级城市的每一年的统计年鉴中的建成区面积作为备用。有人可能会问为什么不以县一级,由于县一级的统计数据一般存在缺失,很难形成一个长时间序列的数据,所以一般采取的是市一级。前文也进行建议,如果确实要基于县一级进行提取可以参考前面理论介绍那篇文章中的相关建议。那么当我们确定阈值后如何将城市建成区提取出来?

端木宛白的博客家园 5403

POJ3696 The Luckiest number 欧拉函数应用

题目链接:http://poj.org/problem?id=3696 题目大意:对于给定的整数L,找出L能整除最短的全8序列的长度,做为Bob的幸运数字。 分析:我们设幸运数字是x,由题意可知,长度为x全8序列为:8/9 * (10^x-1)=L * p,即(10^x-1)=9 * L * p/8。令m=9 * L/gcd(L,8),则存在p',使9 * L * p/8=m

AC_Gibson的专栏 1467

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

poj3696The Luckiest number【欧拉函数】

Language: Default The Luckiest number Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4968   Accepted: 1332 Description Chinese people think of '8' as th

走一步再走一步 780

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

「POJ3696」The Luckiest number【数论,欧拉函数】

题解 一道数论欧拉函数和欧拉定理的入门好题。 虽然我提交的时候POJ炸掉了,但是在hdu里面A掉了,应该是一样的吧。 首先我们需要求的这个数一定可以表示成(10x−1)9×8\frac{(10^x-1)}{9}\times 89(10x−1)​×8。 那么可以列出一个下面的方程 (10x−1)9×8=L×k\frac{(10^x-1)}{9}\times 8=L\times k9(10x−1)​×...

chhokmah的博客 239

POJ - 3696 The Luckiest number 欧拉函数

题目:给你一个数L,找出它的一个倍数x,使得x*L的每一位都是8,输出最小x*L的位数,不存在则输出0 思路:8*(10^k-1)/9=x*L 令r=gcd(8,L),化简 8/r*(10^k-1)=x*(9*L)/r, 因为gcd(8/r,9*L/r)=1, 所以10^k-1=0%(9*L/r) 10^k=1%(9*L/r) 由欧拉函数可以得知有解的条件为gcd(10,9*L/r)

ACVevtor的博客 390

POJ 3696 The Luckiest number 欧拉函数 或 BSGS

原题见POJ 3696给一个数L,问至少几个8(如88,8888,88888)可以整数L。若不能,就输出-1.首先把连续的x个8表示成8+8⋅10+8⋅102+...+8⋅10x−1=8(10x−1)10−18+8·10+8·10^2+...+8·10^{x-1}={8(10^x-1)\over 10-1} 若能整除L,则存在y,使得8(10x−1)9=Ly{8(10^x-1)\over 9}=L

Ugly Gardon 1080

POJ 3696 The Luckiest number(欧拉函数)

 题意:给出一个数L,现在要求一个数A,使得L|A,并且A的每一位都是8,问A的最少位数是多少。 思路: 代码: #include #include #include #include #include #include #include #include #include #include #include #define inf 0x3f3f3f3f #define Inf 0

绝望的乐园 1373

POJ3696 The Luckiest number【欧拉函数】

题目大意: 给你一个数N,问是否存在L的倍数M,且数M各个位上都由8组成,如果存在多个M,输出最小 的那个,并输出M由几个8组成。 思路: 设长度为x,由题意可知,长度为x的由8组成的数可以被L整除。形式为88…88,由于10^x-1是 长度为x、全部由9组成的数,则(10^x-1)/9*8 = L*k(k倍),即(10^x-1)*8= 9*L*k。 则(10^x-1)*8/gcd(8,L) = 9*L*k/gcd(8,L) 令p = 8/gcd(8,L) q = 9*L/gcd(8,L),则(10^x

程序员充电站(itcharge) 1034

poj 3696 The Luckiest number(欧拉函数)

poj 3696 The Luckiest number 由题有 8

yjCola 675

The Luckiest number POJ - 3696(欧拉函数)

The Luckiest number POJ - 3696 题目描述 Chinese people think of ‘8’ as the lucky digit. Bob also likes digit ‘8’. Moreover, Bob has his own lucky number L. Now he wants to construct his luckiest number wh...

FLY_WHITE的博客 245

POJ 3696 The Luckiest Number 【欧拉函数+快速幂】

Description Chinese people think of ‘8’ as the lucky digit. Bob also likes digit ‘8’. Moreover, Bob has his own lucky number L. Now he wants to construct his luckiest number which is the minimum among...

zhaohaibo的博客 450

The Luckiest number POJ - 3696 数学 欧拉函数

Chinese people think of ‘8’ as the lucky digit. Bob also likes digit ‘8’. Moreover, Bob has his own lucky number L. Now he wants to construct his luckiest number which is the minimum among all positiv...

loooooog的博客 213

POJ 3696 The Luckiest Number 欧拉函数

是否存在n能整除的m使m各位都是8。m=89(10x−1)=kn m=\frac{8}{9}(10^x-1) = kn 8⋅10x−1gcd(8,n)=9⋅kngcd(8,n) 8\cdot\frac{10^x-1}{\gcd(8,n)} = 9\cdot\frac{kn}{\gcd(8,n)} 又gcd(8gcd(8,n),ngcd(8,n))=1 gcd\left(\frac{8}{gcd

とある黄鱼のOIブログ 762

The Luckiest number POJ3696(欧拉函数)

The Luckiest number Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his own lucky number L. Now he wants to construct his luckiest number which is the min...

codeswarrior的博客 823
上一篇: Description has only two Sentences HDU - 3307(欧拉函数)(数论定理)
下一篇: TIANKENG’s restaurant HDU - 4883
coldfresh
博客等级 码龄10年 107粉丝 405原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值