一、题面

题目链接:Special Numbers

Theofanis really likes sequences of positive integers, thus his teacher (Yeltsa Kcir) gave him a problem about a sequence that consists of only special numbers.Let's call a positive number special if it can be written as a sum of different non-negative powers of n. For example, for n=4 number 17 is special, because it can be written as 40+42=1+16=17, but 9 is not.Theofanis asks you to help him find the k-th special number if they are sorted in increasing order. Since this number may be too large, output it modulo 1e9+7.Input
The first line contains a single integer t (1≤t≤1e4) — the number of test cases.The first and only line of each test case contains two integers n and k (2≤n≤1e9; 1≤k≤1e9).Output
For each test case, print one integer — the k-th special number in increasing order modulo 1e9+7.Example
input
3
3 4
2 12
105 564
output
9
12
3595374
Note
For n=3 the sequence is [1,3,4,9...]

二、代码分析

一个需要记住的性质

//#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef  pair<int, int> PII;
const int N = 1e6 + 7,mod=1e9+7;void solve()
{int t;cin >> t;while (t--){int n, k;cin >> n >> k;int p = 1;int ans = 0;for (int i = 0; i < 31; i++){if (k & (1 << i)){ans += p;ans %= mod;}p *= n;p %= mod;}cout << ans << endl;}
}signed main()
{//std::ios::sync_with_stdio(false);//cin.tie(0), cout.tie(0);solve();return 0;
}

【二进制】Special Numbers相关推荐

  1. Special Numbers 进制(1100)

    题意 : 写出从小到大第k个满足以下性质的数 :对于给定的n,可以分为若干个不同的n的幂次的和 思路 : 根据题意,这些数是在n进制下,每一位只能取0或者1(出现1次和不出现)的数,考虑将这些数排列, ...

  2. 已知bug列表——Solidity中文文档(12)

    写在前面:HiBlock区块链社区成立了翻译小组,翻译区块链相关的技术文档及资料,本文为Solidity文档翻译的第十二部分<已知bug列表>,特发布出来邀请solidity爱好者.开发者 ...

  3. Codeforces Round #747 (Div. 2) 个人题解

    上蓝了! A. Consecutive Sum Riddle 题意 给一个nnn,你需要构造一个整数区间[L,R][L,R][L,R],其和等于nnn 分析 取[−n+1,n][-n+1,n][−n+ ...

  4. B站收藏6.1w+!这门课拯救你薄弱的计算机基础

    作者 |  Rocky0429 来源 |  Python空间 大家好,我是 Rocky0429,一个对计算机基础一无所知的蒟蒻... 作为一个所谓的计算机科班出身的人来说,特别难为情的是自己的计算机基 ...

  5. JSON 常量详情参考 (内含对中文不转义的参数)

    JSON_ERROR_NONE (integer) 没有错误发生.自 PHP 5.3.0 起生效. JSON_ERROR_DEPTH (integer) 到达了最大堆栈深度.自 PHP 5.3.0 起 ...

  6. B站收藏 12.5w+!GitHub 标星 6.6k+!这门神课拯救了我薄弱的计算机基础

    大家新年好呀,我是你们的 猫哥,我又回来啦 ~ 相信大家过年都过得开心吧 过得开心,那么就开始学习了哈 ~ 前言 作为一个所谓的计算机科班出身的人来说,特别难为情的是自己的计算机基础很差,相信这不是少 ...

  7. 计算机操作系统思维导图_我在b站学计算机

    众所周知,b站成了大家自学的好地方,有大量的极客视频,编程教学,外语教学,甚至还有各个大学公开课,萌宠视频,各国纪录片.up主们真是各显神通.当年小编心心念念的MIT,Harvard计算机教程都没有看 ...

  8. codeforces:ProblemMset

    最近一个月在codeforces上做的题(做个记录) 后面太多了就不把代码一一放出了,只放置了链接,可根据链接找到提交的代码. 最小子矩阵 #include <iostream> #inc ...

  9. Python学习之路21-序列构成的数组

    <流畅的Python>笔记. 接下来的三篇都是关于Python的数据结构,本篇主要是Python中的各序列类型 1. 内置序列类型概览 Python标准库用C实现了丰富的序列类型,可分为两 ...

  10. 2018 ACM ICPC Arabella Collegiate Programming Contest A

    Multiplication operation is not always easy! For example, it is hard to calculate 27 × 20 using your ...

最新文章

  1. OpenCV Laplacian算子
  2. [CareerCup] 11.1 Merge Arrays 合并数组
  3. BNUOJ 52325 Increasing or Decreasing 数位dp
  4. lottie动画_Lottie内存泄漏问题的定位与分析
  5. python 读取xml表结构数据_Python从XML-fi读取数据
  6. python 多层for循环转递归/迭代
  7. 数组和指针(sizeof两者的关系)
  8. 嵌入式linux学习笔记(2)
  9. java phpwind_GitHub - phpwind/windframework: Open-source PHP framework
  10. 东芝300d硒鼓清零代码_东芝300d怎么清?
  11. 怎么把浏览器改成开发者模式_小米手表怎么玩?Wear OS初体验
  12. 大学计算机考核方案,计算机学院学生量化考核评定细则.doc
  13. 【29】CISC和RISC:为什么手机芯片都是ARM?
  14. 高边电流检测测量:电路和原理
  15. HyperLPR车牌识别技术算法之车牌精定位
  16. spark-streaming从入门到精通
  17. 怎么在线免费压缩图片
  18. 数据处理 | MATLAB实现KNN(K近邻)缺失数据填补
  19. 水平集——那些我膜拜过的牛人2
  20. Internet History, Technology and Security (Week5.1)

热门文章

  1. python爬虫爬取豆瓣电影
  2. linux 复制文件时,报cp: omitting directory `XXX'
  3. IT工作十年总结之14个单据通用字段
  4. Silverlight 5 RC新特性探索系列:15.Silverlight 5 RC 对OpenType字体属性的支持
  5. 模式实例之——中介者实例
  6. 构建可扩展的思科互联网络---多区域OSPF
  7. [转]VSS(Visual SourceSafe)使用入门
  8. idea 出现 GC overhead limit exceed解决
  9. postman传各种类型的数组格式
  10. There were no servers available to complete the specified operation