Editorial for Ước chung lớn nhất trong tam giác Pascal
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này
Code mẫu của flashmt
const fi=''; fo=''; maxn=31625; var n:longint; p:array[2..maxn] of byte; b:array[0..3500] of longint; procedure init; var i,j,t:longint; begin t:=trunc(sqrt(maxn)); for i:=2 to t do if p[i]=0 then begin j:=i*i; while j<=maxn do begin p[j]:=1; j:=j+i; end; end; b[0]:=0; for i:=2 to maxn do if p[i]=0 then begin inc(b[0]); b[b[0]]:=i; end; end; function isprime(n:longint):boolean; var i:longint; kt:boolean; begin kt:=true; if n<=b[b[0]] then begin isprime:=p[n]=0; exit; end; for i:=1 to b[0] do if b[i]*b[i]>n then break else begin if n mod b[i]=0 then begin kt:=false; break; end; end; isprime:=kt; end; procedure pr; var i,j,t:longint; begin assign(input,fi); reset(input); assign(output,fo); rewrite(output); read(t); for i:=1 to t do begin read(n); if isprime(n) then writeln(n) else begin for j:=1 to b[0] do if n>=b[j] then begin if n mod b[j]=0 then begin repeat n:=n div b[j]; until n mod b[j]<>0; if n<>1 then writeln(1) else writeln(b[j]); break; end; end else begin writeln(1); break; end; end; end; close(input); close(output); end; begin init; pr; end.
Code mẫu của happyboy99x
#include <algorithm> #include <bitset> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<vii> vvii; typedef vector<int> vi; typedef vector<vi> vvi; #define sz(a) int((a).size()) #define fi first #define se second #define pb push_back #define mp make_pair #define all(c) (c).begin(), (c).end() #define tr(c,i) for(typeof((c).begin()) i = (c).begin(), _e = (c).end(); i != _e; ++i) #define present(c,x) ((c).find(x) != (c).end()) #define cpresent(c,x) (find(all(c),x) != (c).end()) #define rep(i,n) for(int i = 0, _n = (n); i < _n; ++i) #define repd(i,n) for(int i = (n)-1; i >= 0; --i ) #define fo(i,a,b) for(int i = (a), _b = (b); i <= _b; ++i) #define fod(i,a,b) for(int i = (a), _b = (b); i >= _b; --i) #define INF 1000000000 #define N bool prime(int n) { fo(i,2,(int)sqrt(n)) if(n%i==0) return 0; return 1; } int perfect(int n) { for(int i = 0; i < 31; ++i){ double d = pow(n,(double)1/i); if(abs(d - round(d)) < 1e-9 && prime((int) round(d))) return (int) round(d); } return 1; } int main() { int t, n; scanf("%d",&t); while(t--) { scanf("%d",&n); printf("%d\n", perfect(n)); } return 0; }
Code mẫu của RR
//Written by RR {$R-,Q-} {$Mode objfpc} {$inline on} uses math; const FINP = ''; FOUT = ''; MAXN = 100000; var f1,f2 : text; test,n : longint; p : array[1..MAXN] of longint; sl : longint; procedure openF; begin assign(f1,FINP); reset(f1); assign(f2,FOUT); rewrite(f2); end; procedure closeF; begin close(f1); close(f2); end; procedure solve; var save,i,gh,res:longint; begin save:=n; gh:=trunc(sqrt(n)); sl:=0; for i:=2 to gh do if n mod i=0 then begin inc(sl); p[sl]:=i; while n mod i=0 do n:=n div i; end; if n>1 then begin inc(sl); p[sl]:=n; end; if sl>1 then begin writeln(f2,1); exit; end; writeln(f2,p[1]); end; begin openF; read(f1,test); for test:=1 to test do begin read(f1,n); solve; end; closeF; end.
Code mẫu của hieult
#include <stdio.h> //#include <conio.h> #include <math.h> main() { long n[5000],t=2,T,N,x; n[1]=2; n[2]=3; for(long i=4;i<32000;i++) { int k=0; for(long j=1;j<=t;j++) { if(i%n[j]==0) { k=1; break; } else if(n[j]>sqrt(i)) break; } if(k==0) { t++; n[t]=i; } } scanf("%ld",&T); for(long i=0;i<T;i++) { scanf("%ld",&N); int l=0; for(long j=1;j<t;j++) { if(N%n[j]==0) { x=j; do { N=N/n[j]; if(N%n[j]!=0&&N!=1) { l=1; break; } } while(N!=1); break; } else if(n[j]>sqrt(N)) { l=2; break; } } if(l==1) printf("1\n"); else if(l==2) printf("%ld\n",N); else printf("%d\n",n[x]); } //getch(); }
Code mẫu của ll931110
#include <iostream> #define MAXN 34000 #define MAXV 1000000000 using namespace std; int p[MAXN],t,n; bool a[MAXN]; int main() { int i,j,k,nlist,res,tmp; //freopen("gpt.inp","r",stdin); //freopen("gpt.out","w",stdout); for (i = 1; i <= MAXN; i++) a[i] = true; nlist = 0; for (i = 2; i <= MAXN; i++) if (a[i]) { nlist++; p[nlist] = i; k = i; while (k <= MAXN) { a[k] = false; k += i; } } scanf("%d", &t); for (i = 1; i <= t; i++) { scanf("\n"); scanf("%d", &n); res = 1; tmp = n; for (j = 1; j <= nlist; j++) if (n % p[j] == 0) { n = n / p[j]; while (n % p[j] == 0) n = n / p[j]; if (n == 1) res = p[j]; break; } if (tmp == n) res = n; printf("%d\n", res); printf("\n"); } }
Comments