QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#19533 | #1835. Fancy Formulas | foreverlasting# | AC ✓ | 93ms | 3716kb | C++20 | 4.0kb | 2022-02-03 14:13:59 | 2022-05-06 05:43:21 |
Judging History
answer
//2022.2.3 by ljz
//email [email protected]
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
#define res int
#define LL long long
#define Inf 0x3f3f3f3f
#define sup 0x7fffffff
#define inf 0x3f3f3f3f
#define INF 2000000000000000000
//#define unl __int128
#define eps 1e-10
#define RG
#define db double
#define pc(x) __builtin_popcount(x)
#define ctz(x) __builtin_ctz(x)
//#define pc(x) __builtin_popcountll(x)
typedef pair<int,int> Pair;
//#define poly vector<int>
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define ull unsigned LL
#define uint unsigned int
#define lowbit(x) ((x)&-(x))
#define gc getchar
#define ld long db
//template <class T>using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//inline int gc() {
// static char buf[100000],*p1,*p2;
// return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
//char sr[1<<21],z[20];
//int C=-1,Z=0;
//inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
//inline void print(RG LL x){
// if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
// while(z[++Z]=x%10+48,x/=10);
// while(sr[++C]=z[Z],--Z);
//}
template <typename T> inline void Read(T &x) {
res c=gc();
bool f=false;
for(x=0;!isdigit(c);c=gc())if(c=='-')f=true;
for(;isdigit(c);c=gc())x=x*10+c-'0';
if(f)x=-x;
}
inline int read() {
res s=0,ch=gc(),w=1;
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
else if(ch==EOF)break;
ch=gc();
}
while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
return s*w;
}
inline LL Read() {
RG LL s=0;
res ch=gc(),w=1;
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
else if(ch==EOF)break;
ch=gc();
}
while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
return s*w;
}
inline void write(RG __int128 x){
if(x>10)write(x/10);
putchar(int(x%10)+'0');
}
int kcz=998244353;
const int G=3,GI=332748118;
//inline void add(res &x,const res &y){
// x+=y,x>=kcz?x-=kcz:1;
//}
//inline int Add(const res &x,const res &y){
// return x+y>=kcz?x+y-kcz:x+y;
//}
//inline int mul(const res &x,const res &y){
// return int(1ll*x*y%kcz);
//}
#define add(x,y) ((x)+=(y),(x)>=kcz?(x)-=kcz:1)
#define Add(x,y) ((x)+(y)>=kcz?(x)+(y)-kcz:(x)+(y))
#define mul(x,y) (int)((LL)(x)*(y)%kcz)
#define Mul(x,y,d) (int)((ull)(x)*(y)/(d)%kcz)
inline int qpow(res x,res y=kcz-2){
res ret=1;
while(y){
if(y&1)ret=mul(ret,x);
x=mul(x,x),y>>=1;
}
return ret;
}
inline int qpow(res x,res y,const res &ljc){
res ret=1;
while(y){
if(y&1)ret=(int)(1ll*ret*x%ljc);
x=(int)(1ll*x*x%ljc),y>>=1;
}
return ret;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//cloclim_t start=cloclim();
//inline void clim(){
// if(1.0*(cloclim()-start)/CLOCKS_PER_SEC>0.1)exit(0);
//}
//2022.2.3 by ljz
//email [email protected]
//if you find any bug in my code
//please tell me
namespace MAIN{
inline void MAIN(){
kcz=read();
res T=read();
while(T--){
res a=read(),b=read(),c=read(),d=read();
if((a+b)%kcz!=(c+d)%kcz)puts("-1");
else {
res q=qpow(a+b);
a=mul(a,q),c=mul(c,q);
if(a==c)puts("0");
else {
res ret=1;
for(res k=1;;k++){
ret<<=1;
res r=mul(ret,a);
if(Add(r,kcz-c)<ret){printf("%d\n",k);break;}
}
}
}
}
}
}
int main(){
// srand(time(0));
// freopen("18_linked_list.in","r",stdin);
// freopen("1.out","w",stdout);
res Case=1;
for(res T=1;T<=Case;T++)MAIN::MAIN();
// Ot();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3700kb
input:
5 10 2 1 3 0 2 1 4 4 1 3 4 0 0 2 0 4 3 3 1 2 0 1 0 1 0 3 0 3 0 1 0 1 1 2 4 4 1 0 1 1
output:
2 1 2 -1 -1 0 0 0 1 -1
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 26ms
memory: 3712kb
input:
97 100000 30 56 74 12 95 39 8 29 11 42 76 74 48 63 58 53 74 22 85 11 80 23 84 4 30 90 30 90 92 91 41 45 21 82 11 92 65 30 28 67 74 57 95 36 16 31 78 66 2 77 6 73 83 20 41 62 45 44 92 94 96 28 77 47 76 12 87 1 47 80 42 85 46 91 65 72 23 39 4 58 21 96 37 80 83 33 66 50 84 21 61 44 4 78 47 35 39 50 39 ...
output:
6 6 5 6 6 -1 0 4 6 7 7 6 6 2 7 7 6 7 6 4 6 5 5 3 0 4 5 6 6 5 5 5 6 5 5 6 7 -1 5 4 -1 6 4 -1 4 6 5 5 -1 6 6 7 0 -1 2 -1 5 -1 5 7 2 4 6 4 6 6 -1 6 7 6 6 7 6 -1 4 2 7 0 6 -1 6 2 -1 4 6 5 -1 7 3 5 0 -1 7 3 4 6 4 6 0 1 5 7 6 -1 -1 -1 6 5 5 5 3 3 3 -1 -1 2 3 5 6 -1 -1 7 -1 5 7 6 5 6 -1 3 5 5 -1 4 5 6 -1 6...
result:
ok 100000 numbers
Test #3:
score: 0
Accepted
time: 40ms
memory: 3716kb
input:
1217 100000 1084 896 1095 885 1106 523 400 12 1200 37 911 326 992 1098 706 167 917 274 409 782 1154 689 530 96 738 563 879 422 389 1077 1034 432 415 735 61 1089 101 114 388 1044 512 255 818 1166 1149 620 663 1106 655 636 1036 255 86 922 154 854 848 990 740 1098 347 693 534 1192 521 126 866 68 235 36...
output:
9 8 9 7 10 11 8 9 8 9 10 9 10 9 10 -1 -1 10 8 10 10 8 11 10 10 7 -1 7 5 10 -1 9 10 9 8 9 6 10 -1 -1 10 8 9 10 7 9 -1 11 10 8 8 11 -1 -1 8 9 10 11 -1 9 -1 9 8 10 9 10 10 10 6 9 -1 10 10 10 6 10 10 9 10 9 -1 9 6 4 8 9 6 8 10 8 10 10 10 -1 10 10 9 -1 10 11 10 9 8 8 10 9 8 5 7 10 10 9 8 8 8 8 11 11 6 8 ...
result:
ok 100000 numbers
Test #4:
score: 0
Accepted
time: 75ms
memory: 3584kb
input:
999999001 100000 283613712 224836068 452066136 56383644 830489448 158022048 357330405 631181091 920630113 770772345 401855596 289547861 264134671 92704742 146681100 226345536 879982866 896474292 569906689 421772490 229953446 13241605 620830189 622363863 704084273 156005177 727710355 132379095 352992...
output:
29 26 28 -1 -1 27 30 30 30 26 27 -1 29 28 24 -1 30 27 21 -1 28 30 30 30 29 24 -1 30 28 29 -1 29 26 28 29 29 29 29 -1 28 29 29 -1 30 -1 27 26 28 26 30 27 29 30 30 -1 26 30 22 27 30 30 28 29 26 29 29 28 29 28 28 29 25 29 25 25 29 29 27 28 29 28 29 -1 27 -1 -1 27 25 30 -1 27 30 30 29 28 29 29 29 28 28 ...
result:
ok 100000 numbers
Test #5:
score: 0
Accepted
time: 89ms
memory: 3700kb
input:
999999323 100000 24495903 152638425 87217185 794250199 701443586 21540085 848139291 667628831 536695259 167429251 932417987 771705846 949269610 199487801 311910970 836846441 596115883 817268745 835693003 591405497 811816101 156369668 178128049 790057720 999725210 93460875 350432329 742753756 7750141...
output:
-1 -1 30 29 -1 30 27 30 28 25 30 29 29 30 -1 -1 27 28 -1 30 30 27 28 30 27 26 28 28 28 27 22 27 29 25 -1 -1 29 30 29 29 29 28 28 30 30 28 28 27 29 28 29 26 -1 30 28 27 30 30 -1 30 29 30 -1 29 29 30 29 29 29 26 29 29 30 30 30 30 27 29 30 -1 23 -1 28 27 -1 -1 30 -1 29 29 -1 -1 28 26 28 29 27 30 29 26 ...
result:
ok 100000 numbers
Test #6:
score: 0
Accepted
time: 91ms
memory: 3712kb
input:
999999191 100000 920249851 263075456 910189304 273136003 259146706 440590130 217064118 394141081 606425484 261287223 359663798 711610714 633690165 59081357 129380510 563391012 703987751 364076553 981479539 86584765 767987403 851123667 887584320 731526750 634768660 684964613 976154077 343579196 63158...
output:
29 -1 -1 29 28 28 28 29 30 28 28 25 28 28 25 -1 -1 -1 26 28 30 30 30 -1 29 28 27 28 27 -1 -1 30 -1 30 26 30 -1 27 29 -1 -1 29 29 28 29 29 29 26 30 30 28 30 -1 26 28 29 28 26 27 27 -1 29 27 29 -1 23 29 30 25 26 27 27 30 30 30 -1 30 29 24 29 30 -1 28 29 29 29 28 30 24 26 30 30 29 28 27 29 28 28 29 29 ...
result:
ok 100000 numbers
Test #7:
score: 0
Accepted
time: 93ms
memory: 3716kb
input:
1000000007 100000 94813842 786719232 320409267 561123807 612512900 492834218 649856203 487862838 217068316 128383196 301099606 501864265 161142637 582561998 449556540 294148095 641324809 704256785 280041480 991884267 907600109 846641568 611011100 143230570 550215399 866959290 347513960 69660722 6856...
output:
28 -1 -1 27 -1 30 29 29 -1 30 26 29 29 28 29 -1 30 -1 28 26 28 25 28 29 27 27 27 -1 30 30 30 29 30 29 28 28 29 29 -1 28 29 29 29 -1 30 29 28 28 -1 25 28 30 27 28 30 30 -1 29 27 -1 29 29 27 28 28 25 -1 29 -1 30 28 27 29 29 27 29 24 29 29 29 29 -1 25 -1 28 -1 28 29 28 25 29 30 30 29 27 -1 30 30 -1 29 ...
result:
ok 100000 numbers