Educational Codeforces Round 173 (Rated for Div. 2)
A. Coin Transformation
Initially, you have a coin with value \(n\). You can perform the following operation any number of times (possibly zero):
- transform one coin with value \(x\), where \(x\) is greater than \(3\) , into two coins with value \(\lfloor \frac{x}{4} \rfloor\).
What is the maximum number of coins you can have after performing this operation any number of times?
Input
The first line contains one integer \(t\) (\(1 \le t \le 10^4\)) — the number of test cases.
Each test case consists of one line containing one integer \(n\) (\(1 \le n \le 10^{18}\)).
Output
For each test case, print one integer — the maximum number of coins you can have after performing the operation any number of times.
Example
Input
4
1
5
16
1000000000000000000
Output
1
2
4
536870912
Note
In the first example, you have a coin of value \(1\), and you can't do anything with it. So, the answer is \(1\).
In the second example, you can transform a coin of value \(5\) into two coins with value \(1\).
In the third example, you can transform a coin of value \(16\) into two coins with value \(4\). Each of the resulting coins can be transformed into two coins with value \(1\).
题目大意
每次可以将值为 \(x\) 的硬币变为两个值为 \(\lfloor \frac{x}{4} \rfloor\) 的硬币 (\(x\) > \(3\)).问值为 \(x\) 的硬币最多可以获得多少个硬币.
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// 记答案初始为res=1 如果可分数值最小为t=4
// 由题容易看出答案是2的幂次
// 因为x每除4且下取整 答案都会乘2
// 且x最大取1e18 -> 2^60 -> 4^30 所以答案最大也就2^30 可以暴力枚举
void solve(){
ll n;
cin>>n;
ll res=1,t=4;
for(int i=0;i<35;i++){
if(t>n)break;
res*=2;
t*=4;
}
cout<<res<<endl;
}
int main(){
cin.tie(0)->sync_with_stdio(false);
cout.tie(0);
int t;
cin>>t;
while(t--)solve();
}
B. Digits
Artem wrote the digit \(d\) on the board exactly \(n!\) times in a row. So, he got the number \(dddddd \dots ddd\) (exactly \(n!\) digits).
Now he is curious about which odd digits from \(1\) to \(9\) divide the number written on the board.
Input
The first line contains a single integer \(t\) (\(1 \le t \le 100\)) — the number of test cases. The next \(t\) test cases follow.
Each test case consists of a single line containing two integers \(n\) and \(d\) (\(2 \le n \le 10^9\), \(1 \le d \le 9\)).
Output
For each test case, output the odd digits in ascending order that divide the number written on the board.
Example
Input
3
2 6
7 1
8 5
Output
1 3
1 3 7 9
1 3 5 7 9
题目大意
就是去判断 \(dd...ddd\) (\(n!\)个d) 能否被 \(1\) ~ \(9\) 的奇数整除,如果可以就输出。
思路
\(1\) 永远可以。
\(3\) 看 \(d\)%\(3\) 是否为0, 还有看 \(11...111\)%3 是否为 \(0\) (只看数位和即可,即 \(n!\)%3 是否为0)。
\(5\) 只用去看 \(d\) 是否是5即可。
\(7\) 的判断则比较特殊,我的做法是先去判 \(d\) 是否为7, 否则就再去看 \(11...111\)%7 是否为 \(0\).
而这里可以打表
\(1\)%7=1
\(11\)%7=4
\(111\)%7=6
\(1111\)%7=5
\(11111\)%7=2
\(111111\)%7=0
所以当 \(n!\)%6=0 时 \(11...111\)%7 为 \(0\)
\(9\) 看 \(d\)%\(9\) 是否为0, 还有看 \(11...111\)%9 是否为 \(0\), 还有\(d\)%3 为0 且 \(11...111\)%3 是 \(0\)
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// dd...ddd == d * (11..111)
// 然后就是去判断 是否能整除d 是否能整除(11..111)
void solve(){
ll n,d;
cin>>n>>d;
int s3=0,t=n; // 计算n!中3的幂次
while(t){
t/=3;
s3+=t;
}
// 判断x是否能整除 (11..111)
auto check=[&](int x)->bool{
if(x==3)return s3>0; // 对3只要证明 n!是3的倍数即可
if(x==5)return false; // 对5只要证明 d是5的倍数即可
if(x==7) return s3>0; // 对7只要证明 n!是6的倍数即可 或 d==7 打表取mod找规律
return s3>1; // 对3只要证明 n!是9的倍数即可 或 d==9 或 n!%3==0&&d%3==0
};
for(int i=1;i<=9;i+=2){
if(d%i==0||check(i)||(i==9&&d%3==0&&check(3)))cout<<i<<' ';
}
cout<<endl;
}
int main(){
cin.tie(0)->sync_with_stdio(false);
cout.tie(0);
cout<<(11111%7);
int t;
cin>>t;
while(t--)solve();
}

浙公网安备 33010602011771号