結果

問題 No.1203 お菓子ゲーム
ユーザー 👑 PCTprobabilityPCTprobability
提出日時 2020-08-22 13:45:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,799 bytes
コンパイル時間 2,277 ms
コンパイル使用メモリ 197,468 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 03:42:35
合計ジャッジ時間 11,506 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <random>
#include<bits/stdc++.h>
using namespace std;
using ll = 	__int128;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

__int128 p(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}
ll gcds(ll a,ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcds(b, a%b));
   }
}
ll si(ll a,ll b){
  ll r=gcds(a,b);
  return a/r;
}
ll bo(ll a,ll b){
  ll r=gcds(a,b);
  return b/r;
}
int main(){
    ll q,w;
  string o;
  cin>>o;
  ll r;
  ll s=p(o);
 ll a,b;
 assert(1<=s&&s<=100000);
  ll ans;
  string x,y;
  for(ll i=0;i<s;i++){
    cin>>x>>y;
  a=p(x);
    b=p(y);
    assert(1<=a&&a<=10000000&&1<=b&&b<=10000000);
    assert(gcd(a,b)!=1);
    if(2*a>b){
      a=b-a;
    }
ans=100000000/b;
   
    for(ll i=1;i*i<=b;i++){
        
      if(b%i==0){
          if(i%2==1){
          q=(b*(i*i-1))/(2*a*i);
      if((b*(i*i-1))%(2*a*i)==0&&(b*(i*i-1))/(2*a*i)>i&&q>=1&&q<=100000000){
        ans++;
      }
          }
          
      r=b/i;
      if(r!=i){
          if(r%2==1){
          w=(b*(r*r-1))/(2*a*r);
      if((b*(r*r-1))%(2*a*r)==0&&(b*(r*r-1))/(2*a)>r&&w>=1&&w<=100000000){
        ans++;
      }
          }
      }
    }
    }
    cout<<ans<<endl;
  }
}
0