QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#844741 | #9962. Diminishing Fractions | ucup-team6274 | WA | 1ms | 3680kb | C++14 | 3.0kb | 2025-01-06 10:42:23 | 2025-01-06 10:42:23 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
bool Mbg;
using namespace std;
#define vec vector
#define pb push_back
#define eb emplace_back
#define siz(vec) ((int)(vec).size())
#define all(vec) (vec).begin(),(vec).end()
template<class T>
void operator +=(vec<T> &a,T b){a.push_back(b);}
template<class T>
void operator --(vec<T> &a){a.pop_back();}
#define pii pair<int,int>
#define x first
#define y second
#define mp make_pair
#define exc(exp) if(exp)continue;
#define stop(exp) if(exp)break;
#define ret(exp) if(exp)return;
#define deb(var) cerr<<#var<<'='<<(var)<<"; "
#define debl(var) cerr<<#var<<'='<<(var)<<";\n"
#define ins insert
#define era erase
#define lb lower_bound
#define ub upper_bound
#define int long long
#define inf (long long)(1e9)
template<class T>
bool Min(T &x,T y){return x>y?x=y,1:0;}
template<class T>
bool Max(T &x,T y){return x<y?x=y,1:0;}
const int mod=1e9+7;
void Add(int &x,int y){x=x+y<mod?x+y:x+y-mod;}
void Dec(int &x,int y){x=x>=y?x-y:x-y+mod;}
int fpm(int x,int y){
int ans=1;for(;y;y>>=1,(x*=x)%=mod)if(y&1)(ans*=x)%=mod;return ans;
}
void exgcd(int a,int b,int &x,int &y){
if(!b){
x=1,y=0;
}else{
exgcd(b,a%b,y,x);y-=a/b*x;
}
}
int n;
bool nsp[50010];
void sieve(){
for(int i=2;i<=5e4;i++){
if(!nsp[i]){
for(int j=i+i;j<=5e4;j+=i){
nsp[j]=1;
}
}
}
}
int c[50010],a[50010],t[50010];
void work(){
cin>>n;
if(n==1){
cout<<"1/1\n";
return;
}
vec<int> ps;
for(int i=2;i<=n;i++){
exc(nsp[i]);
ps+=i;
c[i]=0,a[i]=1;
while(a[i]*i<=n){
a[i]*=i,++c[i];
}
}
for(int i=2;i<=n;i++){
exc(nsp[i]);
int M=1;
for(auto j:ps){
stop(j>=i);
(M*=a[j])%=a[i];
}
int x,y;
exgcd(a[i],M,y,x);
t[i]=x%a[i];
int mul=1;
for(auto j:ps){
stop(j>=i);
mul*=a[j];
}
y-=mul/a[i]*x;
for(auto j:ps){
stop(j>=i);
(t[j]*=y)%=a[j];
}
}
long double ext=0;
for(int i=1;i<=n;i++){
exc(nsp[i]||!t[i]);
ext+=(long double)t[i]/a[i];
}
int x=-floor(ext+0.3);
bool fir=1;
if(x!=0){
cout<<x<<"/1";
fir=0;
}
for(int i=2;i<=n;i++){
exc(nsp[i]||t[i]==0);
if(!fir&&t[i]>0)cout<<'+';
fir=0;
cout<<t[i]<<'/'<<a[i];
}
cout<<'\n';
}
bool Med;
signed main(){
sieve();
ios::sync_with_stdio(0),
cin.tie(0),cout.tie(0);
int T=1;cin>>T;while(T--)work();
// cerr<<"Time: "<<clock()<<" ms;\n";
// cerr<<"Memory: "<<abs(&Med-&Mbg)/1024.0/1024.0<<" MiB.\n";
}
/*
- CONTINUE, NON-STOPPING, FOR THE FAITH
- START TYPING IF YOU DON'T KNOW WHAT TO DO
- STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3680kb
input:
2 3 6
output:
1/2-1/3 -1/4+2/3-2/5
result:
ok OK, t = 2
Test #2:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
1 1
output:
1/1
result:
ok OK, t = 1
Test #3:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
10 1 2 3 4 5 6 7 8 9 10
output:
1/1 1/2 1/2-1/3 -1/4+1/3 -1/4+2/3-2/5 -1/4+2/3-2/5 -1/1+1/4-1/3+4/5+2/7 -7/8+1/3+2/5+1/7 1/1+3/8-8/9-1/5-2/7 1/1+3/8-8/9-1/5-2/7
result:
ok OK, t = 10
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3608kb
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/1+1/4-1/3+4/5+2/7 1/1-1/16+5/9-2/5-5/7-2/11-9/13+12/17-4/19 1/2 1/2-1/3 -1/4+1/3 -1/4+2/3-2/5 -1/4+2/3-2/5 -1/1+1/4-1/3+4/5+2/7 -7/8+1/3+2/5+1/7 1/1+3/8-8/9-1/5-2/7 1/1+3/8-8/9-1/5-2/7 -1/1-7/8+5/9+4/5+3/7+1/11 -1/1-7/8+5/9+4/5+3/7+1/11 -2/1-3/8+8/9+3/5+4/7+6/11-3/13 -2/1-3/8+8/9+3/5+4/7+6/11-3/1...
result:
wrong answer Sums do not match for modulus 8809877585262195773