题目链接:http://codeforces.com/gym/101061/problem/G

题意:给一个数字n,让你重复m次,求最后这个数对1e9+7取模的结果。

思路:设数字n长度为k,重复m次即 Σ(i,0->m-1)pow(10, k*i)*n。化简公式得到最终结果为n*(pow(10,k*m)-1)/(pow(10,k)-1),要取模所以求一发分母的逆元然后乘进去就行了。我是用exgcd求的逆元,群里有巨巨直接用快速幂把逆元搞出来了,暂时还不太明白原理。

 /*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
//#include <unordered_map>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f7f, sizeof(a))
#define lrt rt << 1
#define rrt rt << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<LL, LL> pll;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const LL mod = ;
LL n, m;
LL len; LL quickmul(LL x, LL q) {
LL ret = ;
while(q) {
if(q & ) ret = (ret * x) % mod;
x = (x * x) % mod;
q >>= ;
}
return ret;
} LL exgcd(LL a, LL b, LL &x, LL &y) {
if(b == ) {
x = ;
y = ;
return a;
}
else {
LL ret = exgcd(b, a%b, x, y);
LL tmp = x;
x = y;
y = tmp - a / b * y;
return ret;
}
} LL mod_inverse(LL a, LL m) {
LL x, y;
exgcd(a, m, x, y);
return (x % m + m) % m;
} int main() {
// FRead();
int T;
Rint(T);
W(T) {
cin >> m >> n;
len = ;
LL tmp = n;
while(tmp) {
len++;
tmp /= ;
}
LL k = m * len;
if(n == ) len = ;
cout << (n*(quickmul(,1LL*len*m)-)%mod*mod_inverse(quickmul(,len)-,mod))%mod << endl;
}
RT ;
}

[CFGym101061G] Repeat it(逆元)的更多相关文章

  1. hdu5651 xiaoxin juju needs help (多重集的全排列+逆元)

    xiaoxin juju needs help 题意:给你一个字符串,求打乱字符后,有多少种回文串.                      (题于文末) 知识点: n个元素,其中a1,a2,··· ...

  2. HDU 5976 数学,逆元

    1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更 ...

  3. mysql while,loop,repeat循环,符合条件跳出循环

    1.while循环 DELIMITER $$ DROP PROCEDURE IF EXISTS `sp_test_while`$$ CREATE PROCEDURE `sp_test_while`( ...

  4. Bzoj2154 Crash的数字表格 乘法逆元+莫比乌斯反演(TLE)

    题意:求sigma{lcm(i,j)},1<=i<=n,1<=j<=m 不妨令n<=m 首先把lcm(i,j)转成i*j/gcd(i,j) 正解不会...总之最后化出来的 ...

  5. CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)

    Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...

  6. 51nod1256(乘法逆元)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1256 题意:中文题诶~ 思路: M, N 互质, 求满足 K ...

  7. O(n)求1-n的逆元

    转自:http://www.2cto.com/kf/201401/272375.html 新学的一个求逆元的方法: inv[i] = ( MOD - MOD / i ) * inv[MOD%i] % ...

  8. MySQL中的while、repeat、loop循环

    循环一般在存储过程和存储函数中使用频繁,这里只给出最简单的示例 while delimiter $$ create procedure test_while() begin declare sum i ...

  9. MySQL-procedure(loop,repeat)

    在 MySQL-procedure(cursor,loop) 中将spam_keyword表中的文字全部分割到t表当中,且每一行的字都不重复,那t表可以用来当作一个小字典,只有1000来个字符,这次把 ...

随机推荐

  1. 【BZOJ】【1042】【HAOI2008】硬币购物

    DP+容斥原理 sigh……就差一点…… 四种硬币的数量限制就是四个条件,满足条件1的方案集合为A,满足条件2的方案集合为B……我们要求的就是同时满足四个条件的方案集合$A\bigcap B\bigc ...

  2. GS线程

    void GameServer::ProcessThread() { try {//在ui线程里面搞个大try不是说try效率不好吗,难道只是为了出现错误发现在GS线程里面出现的吗 ProcessTh ...

  3. fullscreen DXGI DX11

    these days i am fullfilling full screen https://github.com/rufelt/simpled3d11window put this one  in ...

  4. java数组与内存控制

    1.1数组的初始化 数组是大多数编程语言都提供一种的复合结构,如果程序需要多个类型相同的变量时,就可以考虑定义一个数组.java语言的数组变量时引用类型的变量,因此具有java独有的特性. java数 ...

  5. Lessons learned from manually classifying CIFAR-10

    Lessons learned from manually classifying CIFAR-10 Apr 27, 2011 CIFAR-10 Note, this post is from 201 ...

  6. 制作一个可以给team所有成员用的开发者证书

    1. 将证书的private key导出一个.p12的文件给别人 2. 从apple developer网站下载证书对应的provisioning profile 待优化

  7. YARN的 AM与RM通信,申请资源分配过程

    AppMaster向RM请求资源 MRAppMaster :serviceinit // service to allocate containers from RM (if non-uber) or ...

  8. (翻译)Google Guava Cache

    翻译自Google Guava Cache This Post is a continuation of my series on Google Guava, this time covering G ...

  9. 深入理解C# 静态类与非静态类、静态成员的区别

    静态类 静态类与非静态类的重要区别在于静态类不能实例化,也就是说,不能使用 new 关键字创建静态类类型的变量.在声明一个类时使用static关键字,具有两个方面的意义:首先,它防止程序员写代码来实例 ...

  10. 流程控制语句和增强for循环

    import java.lang.Math; //import java.util.Arrays; public class test{ public static void main(String[ ...