QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#189272#3716. Simple ArithmeticCidoai#AC ✓2ms1600kbC++20815b2023-09-27 07:46:152023-09-27 07:46:17

Judging History

你现在查看的是最新测评结果

  • [2023-09-27 07:46:17]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:1600kb
  • [2023-09-27 07:46:15]
  • 提交

answer

#include<cstdio>
typedef long long ll;
typedef __int128 Ln;
inline ll read(){
	ll x=0;
	int f=0,ch=0;
	while(ch<48||ch>57) f=(ch=='-'),ch=getchar();
	while(ch>47&&ch<58) x=(x<<3)+(x<<1)+(ch&15),ch=getchar();
	return f?-x:x;
}
inline void write(Ln x,char end='\n'){
	if(x==0){
		putchar('0');
		putchar(end);
		return;
	}
	if(x<0) putchar('-'),x=-x;
	int ch[70]={0},cnt=0;
	while(x){
		ch[cnt++]=(int)(x%10);
		x/=10;
	}
	while(cnt--) putchar(ch[cnt]+48);
	putchar(end);
}
int main(){
	ll x,y;
	while(~scanf("%lld%lld",&x,&y)){
		Ln a=x,b=y;
		Ln ans=a/b;
		if(a>=0){
			if(b>0){
				if(ans*b>a) ans--;
			}
			else{
				if(ans*b<a) ans--;
			}
		}
		else{
			if(b>0){
				if(ans*b>a) ans--;
			}
			else{
				if(ans*b<a) ans--;
			}
		}
		write(ans);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 1600kb

input:

3 2
3 -2
-9223372036854775808 1
-9223372036854775808 -1
9223372036854775807 1
9223372036854775807 -1
-9223372036854775808 2
-9223372036854775808 -2
9223372036854775807 2
9223372036854775807 -2
-2076046199237518199 8895005889588087898
-3939164353449408 -1673591601308294572
236330652387008908 24746725...

output:

1
-2
-9223372036854775808
9223372036854775808
9223372036854775807
-9223372036854775807
-4611686018427387904
4611686018427387904
4611686018427387903
-4611686018427387904
-1
0
0
-1
-1
2
-2
-1
0
-2
1
0
0
-2
1
0
-37
0
0
3
-1
8
-1
8
-1
-1
-2
0
0
2
8
-1
0
-1
-2
-1
-5
-7
-1
-2
-3
-1
1
0
-11
-1
2
-1
11
8
0
...

result:

ok 9875 tokens