結果
問題 | No.493 とても長い数列と文字列(Long Long Sequence and a String) |
ユーザー |
![]() |
提出日時 | 2017-03-10 23:22:39 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 800 ms |
コード長 | 1,823 bytes |
コンパイル時間 | 1,453 ms |
コンパイル使用メモリ | 163,256 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-24 08:41:48 |
合計ジャッジ時間 | 3,989 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 115 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef signed long long ll;#undef _P#define _P(...) (void)printf(__VA_ARGS__)#define FOR(x,to) for(x=0;x<(to);x++)#define FORR(x,arr) for(auto& x:arr)#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)#define ALL(a) (a.begin()),(a.end())#define ZERO(a) memset(a,0,sizeof(a))#define MINUS(a) memset(a,0xff,sizeof(a))//-------------------------------------------------------ll K,L,R;ll F[100],S[100],P[100];ll mo=1000000007;string ST[100];ll modpow(ll a, ll n = mo-2) {ll r=1;while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;return r;}pair<ll,ll> getval(int K,ll V) {if(V<=0) return {0,1};if(V==F[K]) return {S[K],P[K]};if(V<=F[K-1]) return getval(K-1,V);pair<ll,ll> r = {S[K-1],P[K-1]};V -= F[K-1];ll i;FOR(i,min(V,(ll)ST[K].size())) {char c=ST[K][i];r.first += c;(r.second *= c)%=mo;}if(V>ST[K].size()) {auto b=getval(K-1,V-ST[K].size());r.first += b.first;(r.second *= b.second)%=mo;}return r;}void solve() {int i,j,k,l,r,x,y; string s;F[1]=S[1]=P[1]=1;ST[1]="1";ST[1][0]-='0';for(i=2;i<=61;i++) {F[i]=2*F[i-1];S[i]=2*S[i-1];P[i]=P[i-1]*P[i-1]%mo;char buf[20];sprintf(buf,"%d",i*i);ST[i]=buf;FORR(c,ST[i]) {c-='0';if(c==0) c+=10;F[i]++;S[i]+=c;P[i]=P[i]*c%mo;}}cin>>K>>L>>R;if(K<61 && R>F[K]) return _P("-1\n");auto RR = getval(61,R);if(L>1) {auto LL = getval(61,L-1);cout<<RR.first-LL.first<<" "<<RR.second*modpow(LL.second)%mo<<endl;}else {cout<<RR.first<<" "<<RR.second<<endl;}}int main(int argc,char** argv){string s;int i;if(argc==1) ios::sync_with_stdio(false), cin.tie(0);FOR(i,argc-1) s+=argv[i+1],s+='\n';FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);solve(); return 0;}