× Problem 1007 初始时刻为 0

Problem 1003 请问有何问题

StevenXu | 2020-07-19 17:03:42Author
#include<bits/stdc++.h> using namespace std; int t; bool ifp(int x) { int n = sqrt(x); for(int i=2;i<=n;i++) if(x % i == 0) return 0; return 1; } int solve(int a,int b) { if(a == 1 || b == 1) return a + b - 1; int sum = 0; if(a < b) swap(a, b); while(!ifp(a)) { if(__gcd(a, b) == 1) sum++; a--; } if(a <= b) sum--; sum += a + b - 1; return sum; } int main() { scanf("%d",&t); while(t--) { int a,b; scanf("%d%d",&a,&b); printf("%d\n",solve(a, b)); } for(int i=1;i<=100;i++) if(ifp(i)) cout<<i<<" "; return 0; }
StevenXu | 2020-07-19 17:04:12# 1
#include<bits/stdc++.h> using namespace std; int t; bool ifp(int x) { int n = sqrt(x); for(int i=2;i<=n;i++) if(x % i == 0) return 0; return 1; } int solve(int a,int b) { if(a == 1 || b == 1) return a + b - 1; int sum = 0; if(a < b) swap(a, b); while(!ifp(a)) { if(__gcd(a, b) == 1) sum++; a--; } if(a <= b) sum--; sum += a + b - 1; return sum; } int main() { scanf("%d",&t); while(t--) { int a,b; scanf("%d%d",&a,&b); printf("%d\n",solve(a, b)); } for(int i=1;i<=100;i++) if(ifp(i)) cout<<i<<" "; return 0; }