AtCoder Regular Contest 111 A - Simple Math 2【数学思维】

题意

给出两个数 \(N\)\(M\) ,求出 \(\lfloor \frac{10^N}{M} \rfloor \mod M\) 的值。
\(1≤N≤10^{18},1\leq M \leq 10000\)
题目链接:https://atcoder.jp/contests/arc111/tasks/arc111_a

分析

真没想到可以这样做啊!

问题在于 \(N\) 的数值太大,又没有办法取模,可以转化为取模 \(M^2\)。原因如下:

\[\lfloor \frac{10^N-k*M^2}{M} \rfloor=\lfloor \frac{10^N}{M}-k*M \rfloor=\lfloor \frac{10^N}{M} \rfloor (\mod M)(k∈Z) \]

代码

# -*- coding: utf-8 -*-
"""
Created on Sun Jan 24 19:33:54 2021

@author: hp
"""
n,m=map(int,input().split())
print(pow(10,n,m*m)//m%m)
posted @ 2021-01-24 20:16  xzx9  阅读(85)  评论(0编辑  收藏  举报