This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
#include <queue>
int ps[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int pn=15;
int n;
int data[2223];
typedef std::pair<int,int> pp;
pp dd[2223];
int dp[1<<15];
int M=int(1e9)+7;
bool isprime(int x){
for(int i=2;i*i<=x;++i) if(x%i==0) return 0;
return 1;
}
int getMaxDivisor(int x){
for(int i=x;i>=1;--i) if(x%i==0 && isprime(i)) return i;
return x;
}
int main()
{
int i,j;
scanf("%d",&n);
for(i=0;i<n;++i){
scanf("%d",data+i);
dd[i]={getMaxDivisor(data[i]),data[i]};
}
std::sort(dd,dd+n);
dp[0]=1;
std::queue<pp> pending;
for(i=0;i<n;++i){
int mymask = 0;
int myval = dd[i].second;
for(j=0; j<pn; ++j) if(myval % ps[j]==0) mymask |= (1<<j);
for(j=0; j<32768; ++j){
if((j&mymask) == mymask){
pending.push({j, dp[j^mymask]});
}
}
if(i+1==n || dd[i].first != dd[i+1].first){
while(pending.size()){
pp& tmp=pending.front();
dp[tmp.first]+=tmp.second;
dp[tmp.first]%=M;
pending.pop();
}
}
}
int ans=0;
for(i=0; i<32768; ++i) ans+=dp[i], ans%=M;
printf("%d\n",(ans-n-1+M)%M);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |