Submission #1372823


Source Code Expand

#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=90;
const int mod=1000000007;
ll f[maxn];
typedef pair<ll,ll> pr;
vector<pr> lv[maxn];
int F(ll a,ll b){
  if(a<b)swap(a,b);
  if(a%b==0)return 1;
  return F(b,a%b)+1;
}
void init(){
  f[0]=1;f[1]=1;
  int tot=1;
  while(f[tot]<=1e18){
    ++tot;f[tot]=f[tot-1]+f[tot-2];
  }
  lv[1].push_back(pr(1,2));lv[1].push_back(pr(1,3));
  ll a,b;
  for(int i=2;i<=tot;++i){
    for(vector<pr>::iterator pt=lv[i-1].begin();pt!=lv[i-1].end();++pt){
      a=pt->first;b=pt->second;
      for(int j=1;j<=2;++j){
	if(b*j+a>f[i+2])break;
	if(F(b,b*j+a)==i){
	  lv[i].push_back(pr(b,b*j+a));
	}
      }
    }
    sort(lv[i].begin(),lv[i].end());
    int N=lv[i].size();
    int cnt=0;
    for(int j=0;j<N;++j){
      if(j==0||lv[i][j]!=lv[i][j-1]){
	lv[i][cnt++]=lv[i][j];
      }
    }//printf("%d\n",cnt);
    lv[i].resize(cnt);
  }
  //  printf("%d %lld\n",tot,f[tot]);
}
void work(ll a,ll b){
  if(a==1||b==1){
    if(a==1){
      printf("%d %d\n",1,b%mod);
    }else{
      printf("%d %d\n",1,a%mod);
    }
    return;
  }
  if(a>b)swap(a,b);
  int t=0;
  while(f[t]<=a&&f[t+1]<=b)++t;
  printf("%d ",t-1);
  if(t-1==1)printf("%d\n",a%mod*1ll*(b%mod)%mod);
  else{
    int ans=0;//printf("%d\n",t-2);
    for(vector<pr>::iterator pt=lv[t-2].begin();pt!=lv[t-2].end();++pt){
      ll x=pt->first,y=pt->second;//printf("%d %d\n",x,y);
      if(x>a||x>b)continue;
      if(y<=a)ans=(ans+(b-x)/y)%mod;
      if(y<=b)ans=(ans+(a-x)/y)%mod;
    }
    printf("%d\n",ans);
  }
}
int main(){
  init();int q;scanf("%d",&q);
  ll a,b;
  while(q--){
    scanf("%lld%lld",&a,&b);
    work(a,b);
  }
  return 0;
}

Submission Info

Submission Time
Task F - Kenus the Ancient Greek
User liu_runda
Language C++14 (GCC 5.4.1)
Score 1700
Code Size 1781 Byte
Status AC
Exec Time 615 ms
Memory 4096 KB

Compile Error

./Main.cpp: In function ‘void work(ll, ll)’:
./Main.cpp:49:31: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ll {aka long long int}’ [-Wformat=]
       printf("%d %d\n",1,b%mod);
                               ^
./Main.cpp:51:31: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ll {aka long long int}’ [-Wformat=]
       printf("%d %d\n",1,a%mod);
                               ^
./Main.cpp:59:48: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘ll {aka long long int}’ [-Wformat=]
   if(t-1==1)printf("%d\n",a%mod*1ll*(b%mod)%mod);
                                                ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:72:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   init();int q;scanf("%d",&q);
                              ^
./Main.cpp:75:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with a...

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1700 / 1700
Status
AC × 2
AC × 26
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt AC 321 ms 3328 KB
02.txt AC 320 ms 3328 KB
03.txt AC 320 ms 3328 KB
04.txt AC 320 ms 3328 KB
05.txt AC 321 ms 3328 KB
06.txt AC 322 ms 3328 KB
07.txt AC 321 ms 3328 KB
08.txt AC 320 ms 3328 KB
09.txt AC 320 ms 3328 KB
10.txt AC 321 ms 3328 KB
11.txt AC 615 ms 1920 KB
12.txt AC 615 ms 1920 KB
13.txt AC 218 ms 1920 KB
14.txt AC 219 ms 1920 KB
15.txt AC 246 ms 4096 KB
16.txt AC 246 ms 4096 KB
17.txt AC 144 ms 3840 KB
18.txt AC 144 ms 3840 KB
19.txt AC 528 ms 3584 KB
20.txt AC 528 ms 3584 KB
21.txt AC 4 ms 384 KB
22.txt AC 4 ms 384 KB
23.txt AC 4 ms 384 KB
24.txt AC 4 ms 384 KB
s1.txt AC 4 ms 384 KB
s2.txt AC 4 ms 384 KB