C. K-th Not Divisible by n

C. K-th Not Divisible by n
C.K-不可被n整除

time limit per test: 1 second
每次测试的时间限制:1秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input. standard input
投入。标准输入

output: standard output
产出:标准产出

You are given two positive integers n and k. Print the k-th positive integer that is not divisible by n.
给你两个正整数n和k,打印不可被n整除的第k个正整数。

For example, ifn= 3, andk = 7, then all numbers that are not divisible by 3are: 1,2,4, 5,7, 8, 10, 11, 13… The 7-th number among
例如,IFN=3,k=7,那么所有不能被3整除的数字是:1,2,4,5,7,8,10,11,13.第7位

themis 10.
是10号。

Input
输入

The first line contains an integert(1≤t≤1000)- the number of test cases in the input. Next, t test cases are given, one per line.
第一行包含一个整数(1≤t≤1000)–输入中的测试用例数。接下来,给出t测试用例,每一行一个。

Each test case is two positive integersn(2 < n≤10)andk(1≤k≤109).
每个测试用例是两个正整数(2<n≤10)和k(1≤k≤109)。

Output
输出量

For each test case print the k-th positive integer that is not divisible by n.
对于每个测试用例,打印不可被n整除的k个正整数。

我已经找到了一个绝妙的证明方法,但是这里太窄了,写不下
数论

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n, k,ans;
        cin >> n >> k;
        ans = k+((k-1)/(n-1));
        cout << ans<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Sure, I understand your question. Based on the given conditions, Polycarp likes positive integers that are not divisible by 3 and do not end with the digit 3. We can generate this sequence of numbers as follows: 1, 2, 4, 5, 7, 8, 10, 11, 14, 16, 17, 19, 20, 22, 25, 28, 29, 40, 44, 46, 50, 52, 55, 58, 59, 70, 71, 74, 76, 79, 80, 82, 85, 88, 91, 94, 95, 97, 98, 100, 101, 104, 106, 107, 110, 112, 115, 118, 119, 121, ... To find the k-th element of this sequence, we can simply iterate through the sequence and stop at the k-th element. Here's the code to do that: ``` #include <iostream> #include <vector> using namespace std; bool is_disliked(int n) { return (n % 3 == 0) || (n % 10 == 3); } vector<int> generate_sequence(int n) { vector<int> seq; int i = 1; while (seq.size() < n) { if (!is_disliked(i)) { seq.push_back(i); } i++; } return seq; } int main() { int t; cin >> t; while (t--) { int k; cin >> k; vector<int> seq = generate_sequence(k); cout << seq[k-1] << endl; } return 0; } ``` The `is_disliked()` function checks if a number is disliked by Polycarp based on the given conditions. The `generate_sequence()` function generates the sequence of liked numbers by iterating through all positive integers and adding them to the sequence if they are not disliked. In the main function, we first read in the number of test cases `t`. Then we loop `t` times and for each test case, we read in the value of `k`, generate the sequence of liked numbers of length `k`, and output the k-th element of that sequence.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值