QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#848419 | #9962. Diminishing Fractions | WrongAnswer_90 | WA | 217ms | 7100kb | C++23 | 5.9kb | 2025-01-08 20:23:35 | 2025-01-08 20:23:36 |
Judging History
answer
#include<bits/stdc++.h>
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define ll long long
#define lll __int128
#define fi first
#define se second
#define e emplace
#define eb emplace_back
#define db double
#define ef emplace_front
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vp vector<pii>
#define vt vector<tup>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define FastI
#define FastO
#define int ll
bool ST;
static const ll MOD=1e9+7,Phi=998244352,inv2=499122177,Root=3,iRoot=332748118;
static const ll inf=1073741823,Inf=4294967296,INF=4557430888798830399;
static const ld eps=1e-9,pi=3.1415926535;
char in[1<<20],*p1=in,*p2=in;
char out[1<<20],*p3=out;
using namespace std;
struct tup
{
int x,y;
ll z;
tup(int X=0,int Y=0,ll Z=0)
{x=X,y=Y,z=Z;}
};
#ifdef FastI
#define getchar() (p1==p2&&(p2=(p1=in)+fread(in,1,1<<20,stdin),p1==p2)?EOF:*p1++)
#endif
#ifdef FastO
#define putchar(x) (p3-out==1<<20?fwrite(out,1,1<<20,stdout),p3=out,0:0,*p3++=x)
#define puts(x) write(x,'\n')
#endif
namespace FastIO
{
template<typename T> inline void write(T x,char ch=' ')
{
if(is_same<char,T>::value)putchar(x);
else
{
if(x<0)x=-x,putchar('-');
static char st[25];
int top=0;
do st[top++]=x%10+'0',x/=10;while(x);
while(top)putchar(st[--top]);
}
ch!='~'?putchar(ch):0;
}
inline void write(const char*x,char ch=' ')
{
for(int i=0;x[i]!='\0';++i)putchar(x[i]);
ch!='~'?putchar(ch):0;
}
inline void read(char&s){do s=getchar();while(s=='\n'||s==' ');}
inline void read(char s[])
{
int len=0;char st;
do st=getchar();while(st=='\n'||st==' ');
s[++len]=st,st=getchar();
while(st!='\n'&&st!=' '&&st!='\r')s[++len]=st,st=getchar();
s[++len]='\0';
}
template<typename T> inline void read(T &s)
{
char ch=getchar();s=0;
while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
bool tf=(ch=='-'&&(ch=getchar()));
while(ch>='0'&&ch<='9')s=(s<<1)+(s<<3)+ch-'0',ch=getchar();
s=tf?-s:s;
}
inline void edl(){putchar('\n');}
template<typename T1,typename T2> inline void read(pair<T1,T2> &s){read(s.fi),read(s.se);}
template<typename T,typename...Args> inline void write(T x,Args...args){write(x,'~'),write(args...);}
template<typename T,typename...Args> inline void read(T&x,Args&...args){read(x),read(args...);}
#ifdef FastO
struct Writer{~Writer(){fwrite(out,1,p3-out,stdout);}}Writ;
#endif
}
using namespace FastIO;
namespace MTool
{
inline int Cadd(int a,int b){return (ll)a+b>=MOD?(ll)a+b-MOD:a+b;}
inline int Cdel(int a,int b){return a-b<0?a-b+MOD:a-b;}
inline int Cmul(int a,int b){return 1ll*a*b%MOD;}
inline int sqr(int a){return 1ll*a*a%MOD;}
inline void Madd(int&a,int b){a=((ll)a+b>=MOD?(ll)a+b-MOD:a+b);}
inline void Mdel(int&a,int b){a=(a-b<0?a-b+MOD:a-b);}
inline void Mmul(int&a,int b){a=1ll*a*b%MOD;}
inline int Cmod(int x){return (x%MOD+MOD)%MOD;}
inline void Mmod(int&x){x=(x%MOD+MOD)%MOD;}
template<typename T> inline bool Mmax(T&a,T b){return a<b?a=b,1:0;}
template<typename T> inline bool Mmin(T&a,T b){return a>b?a=b,1:0;}
template<typename...Args> inline void Madd(int&a,int b,Args...args){Madd(a,b),Madd(a,args...);}
template<typename...Args> inline void Mmul(int&a,int b,Args...args){Mmul(a,b),Mmul(a,args...);}
template<typename...Args> inline void Mdel(int&a,int b,Args...args){Mdel(a,b),Mdel(a,args...);}
template<typename...Args> inline int Cadd(int a,int b,Args...args){return Cadd(Cadd(a,b),args...);}
template<typename...Args> inline int Cmul(int a,int b,Args...args){return Cmul(Cmul(a,b),args...);}
template<typename...Args> inline int Cdel(int a,int b,Args...args){return Cdel(Cdel(a,b),args...);}
template<typename...Args,typename T> inline bool Mmax(T&a,T b,Args...args){return Mmax(a,b)|Mmax(a,args...);}
template<typename...Args,typename T> inline bool Mmin(T&a,T b,Args...args){return Mmin(a,b)|Mmin(a,args...);}
// inline int power(int x,int y){int s=1;for(;y;y>>=1,Mmul(x,x))if(y&1)Mmul(s,x);return s;}
}
using namespace MTool;
namespace WrongAnswer_90
{
int n;
void exgcd(int a,int b,int&x,int&y)
{
if(!b)return x=1,y=0,void();
exgcd(b,a%b,x,y);
int z=x;x=y;y=z-x*(a/b);
}
const int N=50000;
vi qu[50010];
bool vis[50010];
int tmp[50010],id[50010];
vp ans[1010];
int P[5210],val[5210];
inline void mian()
{
int x;
read(n);
for(int i=1;i<=n;++i)read(x),qu[x].eb(i);
vi pr;
for(int i=2;i<=N;++i)if(!vis[i])
{
id[i]=pr.size(),pr.eb(i);
for(int j=i*i;j<=N;j+=i)vis[j]=1;
}
for(int i=0;i<(int)pr.size();++i)P[i]=1;
for(auto p:pr)for(int j=p;j<=N;j*=p)tmp[j]=p;
for(int i=2;i<=N;++i)
{
if(tmp[i])
{
P[id[tmp[i]]]=i,val[id[tmp[i]]]=1;
for(int j=0;j<id[tmp[i]];++j)
{
val[j]=val[j]*tmp[i]%P[j];
val[id[tmp[i]]]=val[id[tmp[i]]]*P[j]%i;
}
for(int j=id[tmp[i]]+1;j<(int)pr.size();++j)
{
val[j]=val[j]*tmp[i]%P[j];
val[id[tmp[i]]]=val[id[tmp[i]]]*P[j]%i;
}
}
if(qu[i].size())
{
vp tmp;
for(int i=0;i<(int)pr.size();++i)
if(P[i]>1)tmp.eb(mp(val[i],P[i]));
for(auto p:qu[i])ans[p]=tmp;
}
}
for(int i=1;i<=n;++i)
{
if(ans[i].empty())
{
write(1,'/',1,'\n');
continue;
}
db sum=0;
int vl=0;
for(auto&[x,y]:ans[i])
{
int X,Y;
exgcd(x,y,X,Y),X=(X%y+y)%y;
sum+=1.0*X/y;
if(vl)putchar('+');
vl=1;
int d=__gcd(X,y);
write(X/d,'/',y,'~');
}
if(sum>1)
{
putchar('-');
write((int)floor(sum),'/',1,'~');
}
puts("");
}
}
inline void Mian()
{
int T=1;
// read(T);
while(T--)mian();
}
}
bool ED;
signed main()
{
// ios::sync_with_stdio(0);
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
double st=clock();
WrongAnswer_90::Mian();
double ed=clock();
cerr<<endl;
cerr<<"Time: "<<ed-st<<" ms\n";
cerr<<"Memory: "<<abs(&ST-&ED)/1024.0/1024.0<<" MB\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 214ms
memory: 7088kb
input:
2 3 6
output:
1/2+2/3-1/1 3/4+2/3+3/5-2/1
result:
ok OK, t = 2
Test #2:
score: 0
Accepted
time: 210ms
memory: 7100kb
input:
1 1
output:
1/1
result:
ok OK, t = 1
Test #3:
score: 0
Accepted
time: 217ms
memory: 6468kb
input:
10 1 2 3 4 5 6 7 8 9 10
output:
1/1 1/2 1/2+2/3-1/1 3/4+1/3-1/1 3/4+2/3+3/5-2/1 3/4+2/3+3/5-2/1 1/4+2/3+4/5+2/7-2/1 1/8+1/3+2/5+1/7-1/1 3/8+1/9+4/5+5/7-2/1 3/8+1/9+4/5+5/7-2/1
result:
ok OK, t = 10
Test #4:
score: -100
Wrong Answer
time: 217ms
memory: 7040kb
input:
54 7 20 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 3 47 81
output:
1/4+2/3+4/5+2/7-2/1 15/16+5/9+3/5+2/7+9/11+4/13+12/17+15/19-5/1 1/2 1/2+2/3-1/1 3/4+1/3-1/1 3/4+2/3+3/5-2/1 3/4+2/3+3/5-2/1 1/4+2/3+4/5+2/7-2/1 1/8+1/3+2/5+1/7-1/1 3/8+1/9+4/5+5/7-2/1 3/8+1/9+4/5+5/7-2/1 1/8+5/9+4/5+3/7+1/11-2/1 1/8+5/9+4/5+3/7+1/11-2/1 5/8+8/9+3/5+4/7+6/11+10/13-4/1 5/8+8/9+3/5+4/7...
result:
wrong answer Sums do not match for modulus 8809877585262195773