A. Maximum GCD
题目链接
- 水题,n/2向下取整一定能得到最大的gcd,在此就不证明了(太菜了,不怎么会证,太菜了太菜了。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int t, n;
int main()
{
ios::sync_with_stdio(false);
cin >> t;
while(t--) {
cin >> n;
cout << n/2 << "\n";
}
return 0;
}
B. GCD Compression
- 听了别人的思路有点启发,凑偶数,就统计奇偶元素的个数,然后把索引放进vector里面,如果索引不是偶数,那么就奇偶都扔一个,否则就奇或者偶随便哪个扔两个就行了。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e4+10;
int t, n, a[maxn];
vector<int>e,o;
int main()
{
ios::sync_with_stdio(false);
cin >> t;
while( t-- ) {
cin >> n;
for( int i = 1; i <= 2*n; ++i) cin >> a[i];
for( int i = 1; i <= 2*n; ++i) {
if (a[i] & 1) {
o.push_back(i);
} else {
e.push_back(i);
}
}
if (o.size()&1 != 0){
o.pop_back();
e.pop_back();
} else {
if (o.size() >= 2) {
o.pop_back();
o.pop_back();
} else {
e.pop_back();
e.pop_back();
}
}
while(!o.empty()) {
cout << o.back() << " ";
o.pop_back();
cout << o.back() << "\n";
o.pop_back();
}
while(!e.empty()) {
cout << e.back() << " ";
e.pop_back();
cout << e.back() << "\n";
e.pop_back();
}
}
return 0;
}
C. Number Game
- c我做得很迷,大概就是分解质因数然后看非2质因数的个数和2的个数,按理来说素数筛开到1e7是没法达到要求的,比如像200000006这种数据分解就没法处理,但我鬼使神差的加了一个如果分解遇到1e7以上的数直接让非2质因数个数+1然后结束统计就完了,也过了····至今不知道为啥,我后面再重新写一个叭,这个太玄学了,今晚想睡了,坑明天添
#include<bits/stdc++.h>
using namespace std;
int t, n;
char s1[] = "FastestFinger", s2[] = "Ashishgup";
int rec[10000000 + 10], r[100000 + 10];
int isp()
{
for (int i = 2; i <= 100000; ++i) {
for (int j = 2; j <= 100000 / i + 1; ++j) {
if (i * j < 100000)rec[i * j] = 1;
}
}
int f = 0;
for (int i = 2; i <= 100000; ++i) if (rec[i] == 0) r[f++] = i;
return f;
}
int main()
{
ios::sync_with_stdio(false);
cin >> t;
int f = isp();
while (t--) {
cin >> n;
if (n == 1) {
cout << s1 << "\n";
continue;
}
if (n & 1 || n == 2) {
//printf("%s\n", s2);
cout << s2 << "\n";
continue;
}
int f = 0;
while (n != 1) {
if (n % 2 == 0) {
n /= 2;
f++;
}
else break;
}
if (n == 1) {
//printf("%s\n", s1);
cout << s1 << "\n";
}
else {
int k = 0;
int ti = 1;
while (n != 1) {
if(r[ti]==0){
k++;
break;
}
if (n % r[ti] != 0) ti++;
else {
n /= r[ti];
k++;
}
if (k >= 2) break;
if (r[ti] > n) break;
}
if (k > 1) cout << s2 << "\n";//printf("%s\n", s2);
else {
if (f == 1 || f == 0) cout << s1 << "\n";//printf("%s\n", s1);
else cout << s2 << "\n"; //printf("%s\n", s2);
}
}
}
return 0;
}
D. Odd-Even Subsequence