文章目录

  • A
    • 题目
    • C++代码
  • B
    • 题目
    • 分析
    • C++代码
  • C
    • 题目
    • C++代码

A

题目


Example
input

5
2
2 3 4 5
3
2 3 4 5 5 5
1
2 4
1
2 3
4
1 5 3 2 6 7 3 4

output

Yes
No
No
Yes
No

Note
In the first test case, a possible way of splitting the set is (2,3), (4,5).
In the second, third and fifth test case, we can prove that there isn’t any possible way.
In the fourth test case, a possible way of splitting the set is (2,3).

C++代码

#include <iostream>
#include <algorithm>
using namespace std;int main(){int t;cin >> t;while(t--){int n, a, num_odd=0;cin >> n;for(int i=0; i<2*n; i++){cin >> a;if( a%2==1 )num_odd++;}if(num_odd==n)cout << "Yes" <<endl;elsecout << "No" <<endl;}
}

B

题目

There is an infinite set generated as follows:

  • 111 is in this set.
  • If xxx is in this set, x⋅ax \cdot ax⋅a and x+bx+bx+b both are in this set.

For example, when a=3a=3a=3 and b=6b=6b=6, the five smallest elements of the set are:

  • 111,
  • 333 (111 is in this set, so 1⋅a=31\cdot a=31⋅a=3 is in this set),
  • 777 (111 is in this set, so 1+b=71+b=71+b=7 is in this set),
  • 999 (333 is in this set, so 3⋅a=93\cdot a=93⋅a=9 is in this set),
  • 131313 (777 is in this set, so 7+b=137+b=137+b=13 is in this set).

Given positive integers aaa, bbb, nnn, determine if nnn is in this set.

Input

The input consists of multiple test cases. The first line contains an integer ttt (1≤t≤1051\leq t\leq 10^51≤t≤105) — the number of test cases. The description of the test cases follows.

The only line describing each test case contains three integers nnn, aaa, bbb (1≤n,a,b≤1091\leq n,a,b\leq 10^91≤n,a,b≤109) separated by a single space.

Output

For each test case, print “Yes” if nnn is in this set, and “No” otherwise. You can print each letter in any case.

Example

input

5
24 3 5
10 3 6
2345 1 4
19260817 394 485
19260817 233 264

output

Yes
No
Yes
No
Yes

Note

In the first test case, 242424 is generated as follows:

  • 111 is in this set, so 333 and 666 are in this set;
  • 333 is in this set, so 999 and 888 are in this set;
  • 888 is in this set, so 242424 and 131313 are in this set.

Thus we can see 242424 is in this set.

The five smallest elements of the set in the second test case is described in statements. We can see that 101010 isn’t among them.

分析

当我们对数字+b后再乘a,实际上是加上 a个b,因此每一项SiS_iSi​都满足Si=at+k∗bS_i=a^t+k*bSi​=at+k∗b 我们可以不断枚举ata^tat,然后判断是否能整除bbb即可

C++代码

#include <iostream>
#include <algorithm>
using namespace std;int main(){int t, n, a, b;cin >> t;while(t--){cin >> n >> a >> b;if(a == 1){ if((n - 1) % b == 0)   cout << "Yes" << endl;else    cout << "No" << endl;continue;}int pow = 1, flag = 0;while(n>=pow){if( (n-pow) % b==0){cout << "Yes" << endl;flag = 1;break;}pow *= a;}if(flag==0)cout << "No" << endl;}return 0;
}

C

题目

Let f(i)f(i)f(i) denote the minimum positive integer xxx such that xxx is not a divisor of iii.

Compute ∑i=1nf(i)\sum_{i=1}^n f(i)∑i=1n​f(i) modulo 109+710^9+7109+7. In other words, compute f(1)+f(2)+⋯+f(n)f(1)+f(2)+\dots+f(n)f(1)+f(2)+⋯+f(n) modulo 109+710^9+7109+7.

Input

The first line contains a single integer ttt (1≤t≤1041\leq t\leq 10^41≤t≤104), the number of test cases. Then ttt cases follow.

The only line of each test case contains a single integer nnn (1≤n≤10161\leq n\leq 10^{16}1≤n≤1016).

Output

For each test case, output a single integer ansansans, where ans=∑i=1nf(i)ans=\sum_{i=1}^n f(i)ans=∑i=1n​f(i) modulo 109+710^9+7109+7.

Example

input

6
1
2
3
4
10
10000000000000000

output

2
5
7
10
26
366580019

Note

In the fourth test case n=4n=4n=4, so ans=f(1)+f(2)+f(3)+f(4)ans=f(1)+f(2)+f(3)+f(4)ans=f(1)+f(2)+f(3)+f(4).

  • 111 is a divisor of 111 but 222 isn’t, so 222 is the minimum positive integer that isn’t a divisor of 111. Thus, f(1)=2f(1)=2f(1)=2.
  • 111 and 222 are divisors of 222 but 333 isn’t, so 333 is the minimum positive integer that isn’t a divisor of 222. Thus, f(2)=3f(2)=3f(2)=3.
  • 111 is a divisor of 333 but 222 isn’t, so 222 is the minimum positive integer that isn’t a divisor of 333. Thus, f(3)=2f(3)=2f(3)=2.
  • 111 and 222 are divisors of 444 but 333 isn’t, so 333 is the minimum positive integer that isn’t a divisor of 444. Thus, f(4)=3f(4)=3f(4)=3.

Therefore, ans=f(1)+f(2)+f(3)+f(4)=2+3+2+3=10ans=f(1)+f(2)+f(3)+f(4)=2+3+2+3=10ans=f(1)+f(2)+f(3)+f(4)=2+3+2+3=10.

C++代码

#include <bits/stdc++.h>
#define ll long long
using namespace std;const int mod = 1e9 + 7;ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}int main() {int t;cin >> t;while(t--){ll n;cin>>n;ll ans=n*2;ll cur=1;for(int i=3;i<=43;++i){cur=lcm(cur,i-1);ans=(ans+n/cur)%mod;}cout<<ans<<'\n';   }return 0;
}

Tutorial of Codeforces Round 729 (Div.2)相关推荐

  1. Tutorial of Codeforces Round 729 (Div.2) C. Strange Function

    C. Strange Function 题意 定义一个f(x)为最小的正整数使这个正整数不被x整除,给出一个正整数n,1<=n<=1e16,让求 ∑ i = 1 n f ( i ) \su ...

  2. Codeforces Round #729 (Div. 2)

    Codeforces Round #729 (Div. 2) 题号 题目 知识点 A Odd Set B Plus and Multiply C Strange Function D Priority ...

  3. Codeforces Round #777 (Div. 2) 简训

    Codeforces Round #777 (Div. 2) 简训 导语 涉及的知识点 题目 A Madoka and Math Dad B Madoka and the Elegant Gift C ...

  4. codeforces Round #645 (Div. 2)D题解

    Codeforces Round #645 (Div. 2)--D题解 作为一名菜鸡,理所当然得没有A出来,这道题数据放小就一水题了,可惜数据这块卡的死死的. 本题最重要的一点就是你要推出来一个结论: ...

  5. Codeforces Round #797 (Div. 3)无F

    Codeforces Round #797 (Div. 3)无F 这打的也太屎了,白天把G补了才知道简单的很,但f还是没头绪呜呜呜 Problem - A - Codeforces Given the ...

  6. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  7. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  8. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  9. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

最新文章

  1. python写计算器
  2. leetcode-12-整数转罗马数字
  3. 移除UTF-8文件头的BOM
  4. CSharp设计模式读书笔记(18):中介者模式(学习难度:★★★☆☆,使用频率:★★☆☆☆)...
  5. Java IO(一)
  6. STL15-map/multimap容器
  7. mysql 分享_雷林鹏分享:MySQL 连接
  8. 1.极限——例子_3
  9. android系统功耗优化(2)---Android最佳实践之性能 - 电池续航时间优化
  10. 让你开回家过年!特斯拉计划春节前开始交付国产Model 3
  11. 简单的读取文件和写入文件
  12. android位置模拟源码,android 模拟定位app 源码
  13. ug8.5的java下载_ug nx8.5
  14. python不定长参数_Python可变长参数
  15. 微软开始彻底封杀IE浏览器
  16. HDU 4699 对顶栈
  17. Logical Databases逻辑数据库
  18. word2016(office 365)中安装mathtype相关问题及解决办法
  19. 图神经网络(贪心学院)
  20. 弱网测试(ios手机自带)

热门文章

  1. js解析xml字符串或xml文件,将其转换为xml对象方法
  2. 【c语言】用指针变量输出一维数组中的数据
  3. 原生JS事件中,return false 和 preventDefault() 的区别
  4. 用MediaPlayer record audio简例
  5. python中circle函数_从Python3.6 Zelle Graphics中的另一个函数调用circle函数
  6. a href 下载文件乱码
  7. Bootstraptable源码
  8. 小程序--按钮返回上页
  9. 单元测试工具 unitils
  10. POJ 2723 2-SAT