Hướng dẫn giải của Số phong phú
Chỉ dùng lời giải này khi không có ý tưởng, và đừng copy-paste code từ lời giải này. Hãy tôn trọng người ra đề và người viết lời giải.
Nộp một lời giải chính thức trước khi tự giải là một hành động có thể bị ban.
Nộp một lời giải chính thức trước khi tự giải là một hành động có thể bị ban.
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=''; var x,y,re:longint; a:array[1..100000] of byte; p:array[2..100000] of byte; q:array[0..100000] of longint; procedure prime; var i,j,k:longint; begin fillchar(a,sizeof(a),0); fillchar(p,sizeof(p),0); fillchar(q,sizeof(q),0); for i:=2 to trunc(sqrt(y)) do if p[i]=0 then begin j:=i*i; while j<=y do begin p[j]:=1; j:=j+i; end; end; for i:=2 to y do if p[i]=0 then begin inc(q[0]); q[q[0]]:=i; end; for i:=2 to y do if p[i]=0 then a[i]:=2; for i:=4 to y do if p[i]=0 then begin j:=1; while q[j]*i<=y do begin a[q[j]*i]:=2; inc(j); end; end; end; procedure rf; begin read(x,y); end; function check(x:longint):boolean; var i,j:longint; begin j:=0; for i:=2 to trunc(sqrt(x)) do if x mod i = 0 then j:=j+i+x div i; if sqr(trunc(sqrt(x)))=x then j:=j-trunc(sqrt(x)); check:=(j+1>x); end; procedure pr; var i,j,k:longint; begin prime; re:=0; for i:=x to y do if (i mod 6 = 0) and (i<>6) then a[i]:=1 else begin if a[i]<>0 then continue; if check(i) then begin j:=i; while j<=y do begin a[j]:=1; j:=j+i; end; end; end; for i:=x to y do if a[i]=1 then inc(re); end; procedure wf; begin write(re); end; begin rf; pr; wf; end.
Code mẫu của happyboy99x
#include <cstdio> #define MAX 100000 int s[MAX+5]; void init() { for( int i = 1; i <= MAX; ++i ) for( int j = i+i; j <= MAX; j += i ) s[j] += i; } int main() { init(); int l, r; scanf( "%d%d", &l, &r ); int res = 0; for( int i = l; i <= r; ++i ) res += s[i] > i; printf( "%d\n", res ); return 0; }
Code mẫu của ladpro98
program nkab; var l,r,i,res,j:longint; s:array[1..100000] of longint; begin readln(l,r); for i:=1 to r do begin j:=2; while (i*j<=r) do begin inc(s[i*j],i); inc(j); end; end; for i:=l to r do if s[i]>i then inc(res); write(res); end.
Code mẫu của RR
const MAXN = 100000; var lt,m,p : array[1..MAXN] of longint; sum : array[1..MAXN] of int64; procedure init; var i,gh,j,u:longint; begin gh:=trunc(sqrt(MAXN)); for i:=1 to MAXN do begin p[i]:=i; lt[i]:=1; m[i]:=1; end; for i:=2 to gh do if p[i]=i then begin j:=i*i; u:=i; while (j<=MAXN) do begin p[j]:=i; m[j]:=u; while m[j] mod i=0 do m[j]:=m[j] div i; if m[j]=1 then lt[j]:=lt[u]+1 else lt[j]:=0; inc(j,i); inc(u); end; end; sum[1]:=0; for i:=2 to MAXN do if lt[i]=0 then sum[i]:=sum[m[i]]*sum[i div m[i]] else sum[i]:=(int64(i)*p[i]-1) div (p[i]-1); end; var i,l,r,cnt:longint; begin init; read(l,r); for i:=l to r do if sum[i]-i>i then inc(cnt); writeln(cnt); end.
Code mẫu của hieult
#include <stdio.h> //#include <conio.h> #include <math.h> main() { int a,b,t,x=0,n; scanf("%d %d",&a,&b); n=a; while(n!=b+1) { if(n==1) { n++; continue; } else { if((n%6==0 &&n!=6) || n%20==0) x++; else if(n%2!=0 && n%3!=0); else { t=1; for(int i=2;i*i<=n;i++) { if(i*i==n) t = t+i; else if(n%i==0) t=t+i+n/i; } if(t>n) x++; } n++; } } printf("%d",x); //getch(); }
Code mẫu của ll931110
Program NKABD; Const input = ''; output = ''; Var a: array[1..100000] of longint; l,r: longint; Procedure init; Var f: text; Begin Assign(f, input); Reset(f); Readln(f, l, r); Close(f); End; Procedure sieve; Var i,k: longint; Begin Fillchar(a, sizeof(a), 0); For i:= 1 to 50000 do Begin k:= 2; While k * i <= 100000 do Begin a[k * i]:= a[k * i] + i; inc(k); End; End; End; Procedure solve; Var f: text; i,s: longint; Begin Assign(f, output); Rewrite(f); s:= 0; For i:= l to r do if a[i] > i then inc(s); Writeln(f, s); Close(f); End; Begin init; sieve; solve; End.
Code mẫu của skyvn97
#include<stdio.h> #define MAX 100005 typedef unsigned long long ull; ull s[MAX+10]; ull i,l,r,n; void init(void) { ull i,j; for (i=1;i*2<=MAX;i=i+1) for (j=i*2;j<=MAX;j=j+i) s[j]=s[j]+i; } int main(void) { init(); scanf("%llu",&l); scanf("%llu",&r); n=0; for (i=l;i<=r;i=i+1) if (s[i]>i) n++; printf("%llu",n); return 0; }
Code mẫu của khuc_tuan
// {$APPTYPE CONSOLE} {$mode delphi} var i, j, sum, dem, a, b : integer; begin read(a,b); dem := 0; for i:=a to b do begin sum := 0; for j:=1 to i do begin if j * j > i then break; if sum > i then break; if (i mod j)=0 then begin sum := sum + j; if (j<>1) and (j*j<>i) then sum := sum + i div j; end; end; if sum>i then inc(dem); end; writeln(dem); // readln; readln; readln; end.
Bình luận