結果
問題 | No.752 mod数列 |
ユーザー |
![]() |
提出日時 | 2018-03-09 01:01:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 742 bytes |
コンパイル時間 | 1,979 ms |
コンパイル使用メモリ | 192,904 KB |
最終ジャッジ日時 | 2025-01-05 09:06:16 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
コンパイルメッセージ
main.cpp:11:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type] 11 | main(){ | ^~~~ main.cpp: In function ‘int main()’: main.cpp:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | scanf("%lld",&P); | ~~~~~^~~~~~~~~~~ main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%d",&Q); | ~~~~~^~~~~~~~~ main.cpp:27:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d%d",&L,&R); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll tousa(ll a,ll d,ll n){ return n*(2*a+(n-1)*d)/2; } ll s[32000],t[32000]; main(){ ll P; scanf("%lld",&P); int sn,tn; sn=sqrt(P); tn=P/(sn+1); for(int i=1;i<=sn;++i){ s[i]=s[i-1]+P%i; } for(int i=1;i<=tn;++i){ t[i]=t[i-1]+tousa(P%(P/i),i,P/i-P/(i+1)); } int Q; scanf("%d",&Q); for(int i=0;i<Q;++i){ int L,R; scanf("%d%d",&L,&R); ll sum; if(P<L){ sum=tousa(P,0,R-L+1); }else if(R<=sn){ sum=s[R]-s[L-1]; }else if(sn<L){ sum=tousa(P%L,-P/L,P/(P/L)-L+1); sum+=t[P/L-1]-t[P/R]; sum+=tousa(P%R,P/R,R-P/(P/R+1)); }else{ sum=s[sn]-s[L-1]; sum+=t[tn]-t[P/R]; sum+=tousa(P%R,P/R,R-P/(P/R+1)); } printf("%lld\n",sum); } }