NT的表白(数论)

Problem Description

经过了很长很长的恋爱马拉松,帅气NT(Number Theory)终于决定要向迷人的CG(Computational Geometry)表白了!(对单身汪造成了0x7fffffff点伤害)
CG为了考验NT,于是决定最后再出一道难题。
CG给NT两个整数a,b,说这是我们俩的幸运数字,那么我们孩子(还没结婚就想着孩子= =b)的幸运数字就是1111…1(a个1)%b。
请你大声告诉我,我们孩子的幸运数字是多少!!!!
Input

多组数据,每组数据包括两个整数啊,a,b(1<=a<=10^16, 1<=b<=10^9)
数据组数大约为10000组
Output

对于每组数据,输出一个整数
Sample Input

3 3
4 7
5 18
Sample Output

0
5
5
Hint

111%3=0
1111%7=5
11111%18=5

就是a个1modb多少。
这个是借鉴别人的结论 = =

b | a的前提下
(a/b)mod m = a mod (mb) / b
111…111 % b= ((10^a - 1) / 9) % b = (10^a -1) % (9*b) / 9
直接套用 = =

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
ll pow_mod(ll a,ll n,ll m)
{
    if(n == 0)return 1;
    ll x = pow_mod(a,n/2,m);
    ll ans = x*x%m;
    if(n%2)ans = ans*a%m;
    return ans;
}
int main()
{
    #ifdef LOCAL
    freopen("C:\\Users\\ΡΡ\\Desktop\\in.txt","r",stdin);
    //freopen("C:\\Users\\ΡΡ\\Desktop\\out.txt","w",stdout);
    #endif // LOCAL
    ll a,b;
    while(scanf("%lld%lld",&a,&b)!=EOF)
    {
        ll ans = (pow_mod(10,a,9*b) - 1)%(9*b)/9;
        printf("%lld\n",ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值