Submission #2540370


Source Code Expand

#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<functional>
#include<iterator>
#include<math.h>

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int q;
	scanf("%d", &q);

	int mem[50000] = {};
	mem[0]=-1;
	mem[1]=1;
	mem[2]=1;
	mem[3]=1;
	int l,r;
	int hl,hr;
	int ans=0;
	for(int i=0;i<q;i++){
		scanf("%d %d", &l, &r);

		if(l==1 || l==3){
			hl = 3;
			ans++; 		//hl = 2
		}
		else{
			hl = (l+1)/2;
			if(hl % 2 == 0) hl++;
		}
		hr = (r+1)/2;
											
		for(int j=hl;j<=hr;j+=2){ // jは3以上の奇数
			if(mem[j-1] == 0){  //初
				//cout << "first\n";
				int k;
				for(k=3; k <= j/2; k+=2){
					if(j%k == 0){
						mem[j-1] = -1;
						//cout << "a " <<  j << " " << k << mem[j-1] << "\n";
						break;
					}
				}
				if(k > j/2){

					int J = 2*j-1;
					int kk;
					for(kk=3; kk <= J/2; kk+=2){
						if(J%kk == 0){
							mem[j-1] = -1;
							//cout << "b " <<  j << " " << k << " " << kk << " " << mem[j-1] << "\n";
							break;
						}
					}
					if(kk > J/2){
						mem[j-1] = 1;
						//cout << "c " <<  j << " " << k << " " << kk << " " << mem[j-1] << "\n";
						ans++;
					}	
				}
			}else if(mem[j-1] == 1)	ans++;
		}
		printf("%d\n", ans);
		ans = 0;
	}

	//cout << mem[1] << " " << mem[2] << " " << mem[3] << " " << mem[4] << "\n"; 
	return 0;
}

Submission Info

Submission Time
Task D - 2017-like Number
User osamaki
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1491 Byte
Status TLE
Exec Time 2103 ms
Memory 768 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:20:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
                 ^
./Main.cpp:31:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &l, &r);
                         ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 8
TLE × 2
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
01.txt AC 1210 ms 768 KB
02.txt AC 1213 ms 768 KB
03.txt AC 1205 ms 768 KB
04.txt AC 1209 ms 768 KB
05.txt TLE 2103 ms 640 KB
06.txt TLE 2103 ms 640 KB
07.txt AC 677 ms 768 KB
sample_01.txt AC 1 ms 512 KB
sample_02.txt AC 1 ms 512 KB
sample_03.txt AC 1 ms 512 KB