[传送门]
Let’s consider all integers in the range from 1 to n (inclusive).
Among all pairs of distinct integers in this range, find the maximum possible greatest common divisor of integers in pair. Formally, find the maximum value of gcd(a,b), where 1≤a
The greatest common divisor, gcd(a,b), of two positive integers a and b is the biggest integer that is a divisor of both a and b.
The first line contains a single integer t (1≤t≤100) — the number of test cases. The description of the test cases follows.
The only line of each test case contains a single integer n (2≤n≤106).
For each test case, output the maximum value of gcd(a,b) among all 1≤a
2 1Example
input
3
5output
2Note
In the first test case, gcd(1,2)=gcd(2,3)=gcd(1,3)=1.
In the second test case, 2 is the maximum possible value, corresponding to gcd(2,4).
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define db double
#define inf INT_MAX
#define s(a, n) memset(a, n, sizeof(a))
#define g(a, max) fgets(a, max, stdin)
#define debug(a) cout << '#' << a << '#' << endl
using namespace std;
bool fi = true;
const unsigned long long MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
// 最大公因数即为1到n内最大偶数的1/2
if(n%2==0){
cout << n / 2<<endl;
}
else
cout << (n - 1) / 2 << endl;
}
}
Ashish has an array a of consisting of 2n positive integers. He wants to compress a into an array b of size n−1. To do this, he first discards exactly 2 (any two) elements from a. He then performs the following operation until there are no elements left in a:
The compressed array b has to have a special property. The greatest common divisor (gcd) of all its elements should be greater than 1.
Recall that the gcd of an array of positive integers is the biggest integer that is a divisor of all integers in the array.
It can be proven that it is always possible to compress array a into an array b of size n−1 such that gcd(b1,b2…,bn−1)>1.
Help Ashish find a way to do so.
The first line contains a single integer t (1≤t≤10) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n (2≤n≤1000).
The second line of each test case contains 2n integers a1,a2,…,a2n (1≤ai≤1000) — the elements of the array a.
For each test case, output n−1 lines — the operations performed to compress the array a to the array b. The initial discard of the two elements is not an operation, you don’t need to output anything about it.
The i-th line should contain two integers, the indices (1 —based) of the two elements from the array a that are used in the i-th operation. All 2n−2 indices should be distinct integers from 1 to 2n.
You don’t need to output two initially discarded elements from a.
If there are multiple answers, you can find any.
input
3
3
1 2 3 4 5 6
2
5 7 9 10
5
1 3 3 4 5 90 100 101 2 3output
3 6
4 5
3 4
1 9
2 3
4 5
6 10
In the first test case, b={3+6,4+5}={9,9} and gcd(9,9)=9.
In the second test case, b={9+10}={19} and gcd(19)=19.
In the third test case, b={1+2,3+3,4+5,90+3}={3,6,9,93} and gcd(3,6,9,93)=3.
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define db double
#define inf INT_MAX
#define s(a, n) memset(a, n, sizeof(a))
#define g(a, max) fgets(a, max, stdin)
#define debug(a) cout << '#' << a << '#' << endl
using namespace std;
bool fi = true;
const unsigned long long MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[2005];
int b[505];
int os[2005];
int js[2005];
s(os, 0);
s(js, 0);
s(b, 0);
int osn = 0, jsn = 0;
// 要保证数组b的最大公因数大于一
// 只要保证数组中每个数是偶数即可
for (int i = 0; i < 2 * n; i++) {
cin >> a[i];
if ((a[i] & 1))
os[osn++] = i + 1;
else
js[jsn++] = i + 1;
}
// n=2时 任何答案都符合条件
// 所以直接输出第一个和第二个即可
if (n == 2) {
cout << 1 << ' ' << 2 << endl;
} else {
// n>2时 偶数和偶数配对
// 奇数和奇数配对
// 保证数组b中的每个数都为偶数
if (n - 1 > jsn / 2) {
int i = 0;
for (;; i += 2) {
if (i + 1 < jsn) {
cout << js[i] << ' ' << js[i + 1] << endl;
} else
break;
}
for (int j = 0; i < 2 * n - 2; j += 2, i += 2) {
cout << os[j] << ' ' << os[j + 1] << endl;
}
} else {
int i = 0;
for (;; i += 2) {
if (i + 1 < 2 * n - 2) {
cout << js[i] << ' ' << js[i + 1] << endl;
} else
break;
}
}
}
}
}
Ashishgup and FastestFinger play a game.
They start with a number n and play in turns. In each turn, a player can make any one of the following moves:
Divisors of a number include the number itself.
The player who is unable to make a move loses the game.
Ashishgup moves first. Determine the winner of the game if both of them play optimally.
The first line contains a single integer t (1≤t≤100) — the number of test cases. The description of the test cases follows.
The only line of each test case contains a single integer — n (1≤n≤109).
For each test case, print “Ashishgup” if he wins, and “FastestFinger” otherwise (without quotes).
input
7
1
2
3
4
5
6
12output
FastestFinger
Ashishgup
Ashishgup
FastestFinger
Ashishgup
FastestFinger
Ashishgup
In the first test case, n=1, Ashishgup cannot make a move. He loses.
In the second test case, n=2, Ashishgup subtracts 1 on the first move. Now n=1, FastestFinger cannot make a move, so he loses.
In the third test case, n=3, Ashishgup divides by 3 on the first move. Now n=1, FastestFinger cannot make a move, so he loses.
In the last test case, n=12, Ashishgup divides it by 3. Now n=4, FastestFinger is forced to subtract 1, and Ashishgup gets 3, so he wins by dividing it by 3.
蒟蒻不会博弈论呀 最后一版比赛结束才写出来 tcl 还没交评测姬 仅供参考思路
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define db double
#define inf INT_MAX
#define s(a, n) memset(a, n, sizeof(a))
#define g(a, max) fgets(a, max, stdin)
#define debug(a) cout << '#' << a << '#' << endl
using namespace std;
bool fi = true;
const unsigned long long MOD = 1e9 + 7;
string awin = "Ashishgup";
string fwin = "FastestFinger";
bool isPrime(int num) {
//两个较小数另外处理
if (num == 2 || num == 3) return 1;
//不在6的倍数两侧的一定不是质数
if (num % 6 != 1 && num % 6 != 5) return 0;
int tmp = sqrt(num);
//在6的倍数两侧的也可能不是质数
for (int i = 5; i <= tmp; i += 6)
if (num % i == 0 || num % (i + 2) == 0) return 0;
//排除所有,剩余的是质数
return 1;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
ll n;
cin >> n;
if (n == 1)
cout << fwin << endl;
else if (n == 2)
cout << awin << endl;
else if ((n & 1))
cout << awin << endl;
else {
int newn = (n >> 1);
int flag = 1;
if (isPrime(newn))
;
else {
int size = (newn >> 1);
for (int i = 3; i <= size; i += 2) {
if (newn % i == 0 && newn / i != 1) {
cout << awin << endl;
flag = 0;
break;
}
}
}
if (flag) cout << fwin << endl;
}
}
}