暴力
寄了,超时
#include <iostream>
int gcd(int a,int b) {
if(b == 0) return a;
else return gcd(b,a%b);
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
for(int i = 0;i<n;i++) {
int max = -1;
int x;
std::cin >> x;
for(int i = 1;i<=x;i++) {
for(int j = i+1;j<=x;j++) {
int res = gcd(i,j);
if(max < res) max = res;
}
}
std::cout << max << std::endl;
}
}
用数学公式秒了
#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
for(int i = 0;i<n;i++) {
int x;
cin >> x;
cout << x/2 <<endl;
}
}