Submission #28164

#TimeUsernameProblemLanguageResultExecution timeMemory
28164aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa (#71)The Ethereum and The Bitcoin (FXCUP2_ethereum)C++14
1 / 1
0 ms2164 KiB
#include "ethereum.h" #include <bits/stdc++.h> #define pii pair<int,int> #define pb push_back using namespace std; static int a,b,x,y; static excinfo kinf; static void get(int value){ excinfo tmp = Exchange(value); x = tmp.BTC; y = tmp.ETH; } static long long gcd(long long x,long long y){ return x ? gcd(y%x,x) : y; } static excinfo tmpextgcd(long long a, long long b){ excinfo res, im; // a * BTC + b * ETH = gcd if(!b){ // a = gcd res.BTC = 1, res.ETH = 0; return res; } im = tmpextgcd(b, a%b); long long q = a/b; // a = bq + r : (bq+r) BTC + b ETH = b(q BTC + ETH) + r BTC = gcd res.BTC = im.ETH; res.ETH = im.BTC - q * res.BTC; return res; } static excinfo tmpExchange(long long K,long long B,long long E){ excinfo A; A.BTC = kinf.BTC * K; A.ETH = kinf.ETH * K; if(A.BTC < 0){ long long t = (-A.BTC) / E; A.BTC += t*E, A.ETH -= t*B; if(A.BTC < 0) A.BTC += E, A.ETH -= B; } if(A.ETH < 0){ long long t = (-A.ETH) / B; A.BTC -= t*E, A.ETH += t*B; if(A.ETH < 0) A.BTC -= E, A.ETH += B; } if(A.BTC < 0) A.BTC = A.ETH = -1; return A; } excinfo GetExchangePrice() { int value,cnt = 5; vector<pii> tmp; while(cnt-- && tmp.size() != 1){ if(cnt == 4){ value = 100000000; }else{ value--; } get(value); if(tmp.size() == 0 && x == -1){ }else if(tmp.size() == 0){ for(int i=2; i<=10000; i++){ if(i*x > value) break; if((value-i*x)%y != 0) continue; int j = (value-i*x)/y; if(gcd(i,j) != 1 || j > 10000) continue; tmp.pb({i,j}); } }else{ vector<pii> tmp2; if(x != -1){ for(auto &i : tmp){ if((long long)i.first*x+(long long)i.second*y == value){ tmp2.pb({i.first,i.second}); } } }else{ for(auto &i : tmp){ if(tmpExchange(value,i.first,i.second).BTC != -1) continue; tmp2.pb({i.first,i.second}); } } swap(tmp2,tmp); } } a = tmp[0].first; b = tmp[0].second; excinfo ans; ans.BTC = a; ans.ETH = b; return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...