202. 最幸运的数字 化简 试除法求欧拉函数 欧拉定理 快速幂 快速乘

题目

在这里插入图片描述

题解思路

下面的文章讲的很清楚。
关键是对互质条件推出的公式转移 。

参考文章

AC代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
using namespace std;

const  int  INF =  0x3f3f3f3f ;


long long gehi(long long c )
{
    long long re = c ;
    for (int i = 2 ; i <= c/i ; i++ )
    {
        if ( c % i == 0 )
        {
            while ( c % i == 0 )
                c /= i ;
            re = re / i *( i - 1 ) ;
        }
    }
    if ( c > 1 )
        re = re / c * ( c - 1 );
    return re ;
}
long long gsc (long long a , long long b , long long mo )
{
    long long re = 0 ;
    while( b )
    {
        if ( b & 1 ) re =( re + a )% mo ;
        a = (a  + a ) % mo ;
        b >>= 1 ;
    }
    return re ;
}

long long qmi ( long long di , long long mi , long long mo )
{
    long long re = 1 ;
    while( mi )
    {
        if ( mi & 1 )  re =  gsc( re , di , mo ) ;
        di = gsc( di , di , mo );
        mi >>= 1 ;
    }
    return re ;
}


int main ()
{
    ios::sync_with_stdio(false);
    long long   l;
    int tt = 1 ;
    while( cin >> l && l )
    {
        int d = __gcd( (long long )8 ,l );
        long long  c = 9*l /d ;

        long long phi =  gehi(c) ;

        long long ans = 1e18 ;
   //     cout << phi << " " << c <<"\n";
        if ( c % 2 == 0 || c % 5 == 0 )
            ans = 0 ;
        else
        {
            for ( long long i = 1 ; i * i <= phi ; i++ )
            {
                if ( phi % i == 0 )
                {
                    if ( qmi( 10 , i , c ) == 1 )
                        ans = min ( ans , i ) ;
                    if ( qmi( 10 , phi / i , c ) == 1 )
                        ans = min ( ans , phi / i ) ;
                }

            }
        }
        cout << "Case " << tt << ": " <<  ans   << "\n";
        tt++;
    }

    return 0 ;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值