1001
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);++i)
#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define DWN(i,b,a) for(int i=int(b);i>=int(a);--i)
/// type define
typedef double DB;
typedef long long LL;
typedef std::vector<int>VI;
typedef std::vector<LL>VLL;
typedef std::pair<int, int>PII;
typedef std::pair<LL, LL>PLL;
typedef std::vector<PII >VPII;
/// const
static const double eps = 1e-8;
static const double pi = acos(-1.0);
static const int inf = 0x3f3f3f3f;
static const LL INF = 0x3f3f3f3f3f3f3f3f;
/// common statement
#define PB push_back
#define MP std::make_pair
#define fi first
#define se second
/****************************************************************/
const int maxn = 2e6 + 7;
const LL MOD = 1e9 + 7;
int a[maxn],b[maxn];
void solve() {
/*********** start your code here. ************/
int n;
std::cin >> n;
REP(i,n) std::cin >> a[i];
REP(i,n) std::cin >>b[i];
for(int i = n-1; i >= 0; --i) {
int x = a[i],y = b[i];
if(a[i] || b[i]) {
if(!x)
puts("0/1");
else if(!y)
puts("1/0");
else {
int z = std::__gcd(x,y);
x /= z,y /= z;
std::cout << x << "/" << y << "\n";
}
break;
}
}
}
void init() {
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
init();
int T;
std::cin >>T;
while(T--)
solve();
return 0;
}
1005
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);++i)
#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define DWN(i,b,a) for(int i=int(b);i>=int(a);--i)
/// type define
typedef double DB;
typedef long long LL;
typedef std::vector<int>VI;
typedef std::vector<LL>VLL;
typedef std::pair<int, int>PII;
typedef std::pair<LL, LL>PLL;
typedef std::vector<PII >VPII;
/// const
static const double eps = 1e-8;
static const double pi = acos(-1.0);
static const int inf = 0x3f3f3f3f;
static const LL INF = 0x3f3f3f3f3f3f3f3f;
/// common statement
#define PB push_back
#define MP std::make_pair
#define fi first
#define se second
/****************************************************************/
const int maxn = 2e6 + 7;
const LL MOD = 1e9 + 7;
LL C(LL x){
LL step[] = {3,4,3,1,6,1};
LL b[] = {0,1,1,0,3,0};
return b[x%6]+x/6*step[x%6];
}
void solve() {
/*********** start your code here. ************/
LL n;std::cin >>n;
std::cout << C(n) << "\n";
}
void init() {
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
//init();
int T;
std::cin >>T;
while(T--)
solve();
return 0;
}
原文:https://www.cnblogs.com/Forgenvueory/p/11374092.html