Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求解数据问题

Posted by hanyin at 2016-03-26 16:31:02 on Problem 2773
#include <cstdio>
#include <algorithm>
#include<math.h>
#include<string.h>
#include<memory.h>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include <stdio.h>
#include <stack>
#include <set>
#define MOd 0x7FFFFFFF;
#define mod 65537;
typedef  long long LL;
using namespace std;
int m,k;
int prime[1000000],num[1000000],num2[3000000];

void eluer(){
for(int i=2;i<=1000000;i++){
    if(prime[i]==0){
        for(int j=i+i;j<=1000000;j+=i)
            prime[j]=1;

}

}
}

int main(){
freopen("in.txt","r",stdin);
  prime[1]=0;
  eluer();
while(~scanf("%d%d",&m,&k)){
        int i,j;
if(m==1){
    cout<<k<<endl;
    continue;
}
int fg=0;
fg++;
num[fg]=1;
//memset(num2,0,sizeof(num2));
for(i=1;i<=m;i++)
    num2[i]=0;
for(i=2;i<=m;i++){
    if(prime[i]==0&&m%i==0){
        for( j=i;j<=m;j+=i)
        num2[j]=1;
    }
}
for(i=2;i<=m;i++){
    if(num2[i]!=1){
        fg++;
        num[fg]=i;
  //  cout<<i<<endl;
    }

}
long long t=k/fg;
k=k%fg;
if(k==0)
    k=fg,t--;
long long sum=t*m+num[k];
cout<<sum<<endl;
}
    return 0;
}

为什么num2开到1000000就会re,开到3000000就过了orz

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator