QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#863828#3004. It's a Mod, Mod, Mod, Mod WorldisWFnoya#TL 0ms0kbC++261.0kb2025-01-19 23:13:042025-01-19 23:13:04

Judging History

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

  • [2025-01-19 23:13:04]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2025-01-19 23:13:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1919810;
typedef long long ll;
typedef pair<ll,ll> PII;

ll p,q,n;
int a[N],b[N];
char s[N],t[N];
ll dp[N][114];
ll gg,fjd,cnt,tot,base;
ll cal1(ll x){
    ll cc=x/cnt;
    ll mul=cnt*q;
    ll res=(fjd+fjd+cc-1)*cc/2*mul;
    x%=cnt;
    ll ffjd=fjd+cc;
    res+=ffjd*q*x;
    // cout<<"--"<<res<<endl;
    return res;
}


void __(){
    scanf("%lld%lld%lld",&p,&q,&n);
    
    //  n++;
    p%=q;
    if(p==0){
        puts("0");
        return;
    }
    gg=__gcd(p,q);
     fjd=q%p;
    cnt=q/p;
    tot=q/gg;
     base=(q-gg)*(tot)/2;
    ll ans=base*(n/q);
    // ans+=(1+n)*n/2*p;
    n%=tot;
    ll val=0;
    // cout<<ans<<endl;
    for(int i=1;i<=n;i++){
        val+=p;
        if(val>=q) val-=q;
        // cout<<val<<endl;
        ans+=val;
    }
    printf("%lld\n",ans);
}
//3 4 7
//0 3
//2
//1
//7 4 1 8 5 2
//0 3 6
//1 4 7
//2 5 
//0 2 4 6


int main(){
    int _=1;
    cin>>_;
    while(_--){
        __();
    }
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

91125
999956 999956 999956
999956 999956 999957
999956 999956 999958
999956 999956 999959
999956 999956 999960
999956 999956 999961
999956 999956 999962
999956 999956 999963
999956 999956 999964
999956 999956 999965
999956 999956 999966
999956 999956 999967
999956 999956 999968
999956 999956 999969
...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
499956500946
499956500946
499957500902
499958500857
499959500811
499960500764
499961500716
499962500667
499963500617
499964500566
499965500514
499966500461
499967500407
499968500352
499969500296
499970500239
49...

result: