最小的数
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 14 Accepted Submission(s) : 8
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
定义一种正整数集合K,集合中有N个数,集合中元素Ki(1<=i<=N)是包含i个不同质因子的最小的数。因为Ki可能会很大,所以将集合中所有Ki对10^9+7取余。
Input
本题只有唯一一组测试数据,第一行给出N,q,表示K的个数以及q次询问。1<=N<=1000,q<=10^5.
接下来q行每行一个正整数(64位整数范围内),请判断其对10^9+7取余后,是否在集合K中。
Output
对于每次询问,根据题意输出Yes或No
Sample Input
Sample Output
Yes
Yes
No
1 #include<iostream>
2 #include<stdio.h>
3 using namespace std;
4 long long num[1005];//特别注意这个数组虽然要是取余的值,但是在求下一个数的时候可能会爆了int,比赛的时候就错在这
5 int s[1005];
6 bool su(int x){
7 if(x==1) return true;
8 else if(x==2) return true;
9 else if(x%2==0) return false;
10 else {
11 for(int i=3;i*i<=x;i=i+2){
12 if(x%i==0) return false;
13 }
14 return true;
15 }
16 }
17 int main()
18 {
19 int t=1;
20 for(int i=1;t<=1005;i++)
21 if(su(i)) s[t++]=i;
22 num[1]=1;
23 for(int i=2;i<=1002;i++){
24 num[i]=(num[i-1]*s[i])%1000000007;//这地方可能会爆
25 }
26 int n,q;
27 cin>>n>>q;
28 long long xx;
29 for(int i=0;i<q;i++)
30 {
31 scanf("%lld",&xx);
32 int x,flag=0;
33 x=xx%1000000007;
34 for(int j=1;j<=n;j++){
35 if(x==num[j]){
36 flag=1;
37 break;
38 }
39 }
40 if(flag)
41 cout<<"Yes"<<endl;
42 else
43 cout<<"No"<<endl;
44 }
45 return 0;
46 }