QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#844738 | #9962. Diminishing Fractions | ucup-team6274 | WA | 1ms | 3632kb | C++14 | 2.9kb | 2025-01-06 10:41:43 | 2025-01-06 10:41:48 |
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;
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: 0ms
memory: 3632kb
input:
2 3 6
output:
1/2-1/3 -1/4+2/3-2/5
result:
ok OK, t = 2
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3620kb
input:
1 1
output:
result:
wrong answer Not enough lines of fractions for the 1th test case