UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215343#2478. 数!!naroto2022Compile Error//C++1.3kb2024-11-28 20:08:082024-11-28 23:11:15

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#define ll long long
using namespace std;
const int MN=5005,MM=40005;
ll n,m,a[MN],b[MN],g[MN],ans;
vector<ll> p;
map<ll,ll> mp,rem;
void write(ll n){if(n<0){putchar('-');write(-n);return;}if(n>9)write(n/10);putchar(n%10+'0');}
ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
void init(){
    vector<ll> vis(MM);
    for(int i=2; i<MM; i++){
        if(!vis[i]) p.push_back(i);
        for(int j:p){
            if(i*j>MM) break;
            vis[i*j]=1;
            if(i%j==0) break;
        }
    }
}
ll f(ll x) {
	if(rem.count(x)) return rem[x];
	ll ret=0,y=x;
	for(int i:p){
		ll cnt=0;
		while(y%i==0) y/=i,cnt++;
		ret+=cnt*(mp[i]?-1:1);
		if(y==1) break;
	}
	if(y>1) ret+=(mp[y]?-1:1);
	return rem[x]=ret;
}
int main(){
    init();
    n=read();m=read();
    for(int i=1; i<=n; i++){a[i]=read();g[i]=gcd(g[i-1],a[i]);}
    for(int i=1; i<=m; i++){b[i]=read();mp[b[i]]=1;}
    for(int i=1; i<=n; i++) ans+=f(a[i]);
    for(int i=n,cnt=1,tmp; i; i--) if((tmp=f(g[i]/cnt))<0) ans-=tmp*i,cnt=g[i];
    write(ans);putchar('\n');
    return 0;
}

详细

answer.code: In function 'void init()':
answer.code:21:19: error: range-based 'for' loops are not allowed in C++98 mode
         for(int j:p){\x0d
                   ^
answer.code: In function 'long long int f(long long int)':
answer.code:31:12: error: range-based 'for' loops are not allowed in C++98 mode
  for(int i:p){\x0d
            ^