社区讨论
99pts WA on #10 萌新求调
P3518[POI 2011] SEJ-Strongbox参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mhj3g0ru
- 此快照首次捕获于
- 2025/11/03 20:05 4 个月前
- 此快照最后确认于
- 2025/11/03 20:05 4 个月前
CPP
#include <bits/stdc++.h>
namespace my_std{
#define one_case int tt = 1; while(tt--)
#define multi_case int tt; cin>>tt; while(tt--)
#define fir(i,a,b) for(int i=(a);i<=(b);++i)
#define rif(i,a,b) for(int i=(a);i>=(b);++i)
#define For(i,a,b) for(auto i=(a);i!=(b);++i)
using LL = long long;
const int Mod = 1e9+7;
template<class T> void qmod(T &x){ x = x<0 ? x+Mod : (x>=Mod ? x-Mod : x); }
template<class T> T Qmod(T x){ return x<0 ? x+Mod : (x>=Mod ? x-Mod : x); }
using lf = double;
const double eps = 1e-10;
using pii = std::pair<int,int>;
template<class T1,class T2> auto cp(T1 x,T2 y){
return std::make_pair(x,y);
}
template<class T1,class T2> std::istream & operator >> (std::istream &in, std::pair<T1,T2> &A){
in >> A.first >> A.second;
return in;
}
template<class T1,class T2> std::ostream & operator << (std::ostream &ot, std::pair<T1,T2> &A){
ot << "(" << A.first << "," << A.second <<")";
return ot;
}
using vi = std::vector<int>;
template<class T> std::istream & operator >> (std::istream &in,std::vector<T> &A){
size_t Size = A.size();
For(i,1,Size){
in >> A[i];
}
return in;
}
template<class T> std::ostream & operator << (std::ostream &ot,std::vector<T> &A){
size_t Size = A.size();
For(i,0,Size){
ot << A[i]; ot << (i!=Size-1 ? "," : "");
}
return ot;
}
template<class T> T Abs(T x){
return x>0 ? x : -x;
}
template<class T> T Gcd(T x,T y){
if(!y) return x;
return Gcd(y,x%y);
}
template<class T> class PQ{
private:
std::priority_queue< T,std::vector<T>,std::greater<T> > q1;
std::priority_queue< T,std::vector<T>,std::greater<T> > q2;
public:
void Insert(T x){
q1.push(x);
}
void Delete(T x){
q2.push(x);
}
bool Empty(){
while(!q1.empty() and !q2.empty() and q1.top()==q2.top()){
q1.pop();
q2.pop();
}
return q1.empty();
}
T Top(){
return q1.top();
}
};
void Ios(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
void Finish_Coding(){
}
template<class ... Args> void Print(Args ... args){
size_t count = 0;
( (std::cerr << (count++ ? "," : "") << args), ...);
}
#ifdef DEBUG
#define DDebug(...) \
cerr << "@" << __func__ << ",#" << __LINE__ << ": ["; \
Print(#__VA_ARGS__); \
cerr << "] = {"; \
Print(__VA_ARGS__); \
cerr << "}\n";
#define ddebug(...) \
"@" << __func__ << ",#" << __LINE__ << ": [" << #__VA_ARGS__ << "] = {" << __VA_ARGS__ << "}"
#else
#define DDebug(...) void(0)
#endif
}using namespace my_std;
using namespace std;
LL n; int k;
signed main(){
string __name = "";
if(__name!=""){
freopen((__name+".in").c_str(),"r",stdin);
freopen((__name+".out").c_str(),"w",stdout);
}
one_case[&]{
cin >> n >> k;
vector<LL> m(k+1);
cin >> m;
LL mx = Gcd(n,m[k]);
DDebug(mx);
vector<LL> pri;
auto pre = [&](){
LL x = mx;
for(LL d = 2; d*d<=x; ++d){
if(x%d == 0){
pri.emplace_back(d);
while(x%d == 0){
x/=d;
}
}
}
if(x != 1){
pri.emplace_back(x);
}
}; pre();
DDebug(pri);
map<LL,bool> vis;
auto bfs = [&](){
queue<LL> q;
fir(i,1,k-1){
m[i] = Gcd(m[i],mx);
if( !vis.count(m[i]) ){
q.push(m[i]);
vis[ m[i] ] = 1;
}
}
while(!q.empty()){
LL u = q.front(); q.pop();
for(LL d : pri){
if(LL v = u/d; v*d == u and !vis.count(v) ){
q.push(v);
vis[v] = 1;
}
}
}
}; bfs();
LL g = mx;
auto qry = [&](){
LL x = mx;
for(LL d = 2; d*d<=x; ++d){
if(x%d == 0){
if(x%d == 0){
if( !vis.count(d) ){
g = d;
return;
}
if( !vis.count(x/d) ){
g = x/d;
}
}
}
}
}; qry();
DDebug(g);
cout << n / g << '\n';
}();
Finish_Coding();
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...