1001
签到,按题意模拟
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
#define endl '\n'
#define ull long long
const int N = 200005;
const ll mod = 998244353;
ll p = N-1;
ll lowbit(ll x) {
return x & (-x);
}
ll gcd (ll a,ll b) {
return b==0 ? a : gcd(b,a%b);
}
ll powmod(ll a, ll b, ll mod) {
ll ret = 1;
for (; b; b >>= 1) {
if (b & 1) ret = ret * a % mod;
a = a * a %mod;
}
return ret;
}
ll a[N];
void solve() {
int n;
cin>>n;
ll ans=1;
for(int i=1;i<=n;i++) {
cin>>a[i];
ans*=a[i]+1;
ans%=mod;
}
if(ans!=0)
cout<<ans-1<<endl;
else cout<<"0"<<endl;
}
int main() {
ios::sync_with_stdio(false) ,cin.tie(0);
int t;
cin>>t;
while(t--) {
solve();
}
}
1007
其实就是数学题,线性筛完之后,容斥原理,这是爆搜写法,就是说,每多乘一个数符号改变一次。
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
#define endl '\n'
#define ull long long
const int N = 10000005;
const ll mod = 998244353;
int prime[N/10],f[N];
int n;
bool p[N];
set <int> S;
vector <int> v;
int m,ret;
void qprime(int x) {
int cnt = 0;
for(int i=2;i<=n;i++) {
if(!p[i]) prime[++cnt] = i,f[i] = i;
for(int j=1;j<=cnt && prime[j]*i<=n ; j++ ) {
p[prime[j]*i] = 1;
f[prime[j]*i] = prime[j];
if(i%prime[j]==0) break;
}
}
}
void fj(int x) {
while(x>1) {
int y=f[x];
if(S.find(y) == S.end()) S.insert(y);
while (x%y==0) x/=y;
}
}
void dfs(int x,int s,int o) {
if(x == m) {
ret += o*(n/s);
return ;
}
dfs(x+1,s,o);
if(s <= n/v[x]) dfs(x+1,s*v[x],-o);
}
int calc(int x,int y ){
S.clear();
fj(x),fj(y);
v.clear();
for(auto x:S ) v.push_back(x) ;
int sz = v.size();
ret = 0;
dfs(0,1,1);
return ret;
}
int gcd (int x,int y) {
return y==0 ? x : gcd(y,x%y);
}
void solve() {
int u,v;
cin>>u>>v;
if(gcd(u,v)==1) {
cout<<"1"<<" "<<1<<endl;
return ;
}
int ans = 0;
if(gcd(u,v)==2) {
ans ++;
}
ans += calc(u,v);
cout<<2<<" "<<ans<<endl;
}
int main() {
ios::sync_with_stdio(false) ,cin.tie(0);
cin>>n;
qprime(n);
int t;
cin>>t;
while(t--) {
solve();
}
}