Submission #2407921


Source Code Expand

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int calc(int a, int b) {
	if (a==b) return (a-1)*2;
	if (a>b) swap(a, b);
	
	int res = a-1;
	long long int m = 1LL*a*b-1;
	/*long long int lo = a+2, hi = m, pos;
	while(lo<=hi) {
		long long int mi = (lo+hi)/2;
		if (m/mi == m/(mi-1) || mi>a+2 && m/(mi-1)==m/(mi-2)) {
			pos = mi;
			hi=mi-1;
		} else lo=mi+1;
	}
	printf("- %d\n", pos);
	return res + pos-1-a + m/pos-1;*/
	long long int it = a+1, y=m/it, x;
	long long ran = sqrt(m-1);
	if (ran > it) {
		res += ran-1-it; it=ran-1;
	}
	do {
		res++;
		it++;
		x=y; y = m/it;
	} while (y!=x);
	//printf("- %d\n", it-ran);
	return res + y-1;
}

int main() {
	int q, a, b;
	for(scanf("%d", &q); q--;) {
		scanf("%d%d", &a, &b);
		printf("%d\n", calc(a, b));
	}
	
	return 0;
}

Submission Info

Submission Time
Task D - Worst Case
User maryanna2016
Language C++14 (GCC 5.4.1)
Score 700
Code Size 842 Byte
Status AC
Exec Time 12 ms
Memory 128 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:38:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  for(scanf("%d", &q); q--;) {
                     ^
./Main.cpp:39:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
                        ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 1
AC × 12
Set Name Test Cases
Sample s1.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, s1.txt
Case Name Status Exec Time Memory
01.txt AC 1 ms 128 KB
02.txt AC 1 ms 128 KB
03.txt AC 1 ms 128 KB
04.txt AC 1 ms 128 KB
05.txt AC 12 ms 128 KB
06.txt AC 1 ms 128 KB
07.txt AC 3 ms 128 KB
08.txt AC 4 ms 128 KB
09.txt AC 3 ms 128 KB
10.txt AC 3 ms 128 KB
11.txt AC 1 ms 128 KB
s1.txt AC 1 ms 128 KB