Hướng dẫn giải của Dãy chia hết
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
var n,re:longint; i,j,k,t:longint; begin read(n); j:=0; k:=0; while j<n do begin inc(k); j:=j+k; end; t:=n-(j-k); re:=1; for i:=2 to k-1 do re:=re+i-re mod i+i*(i-1); re:=re+k-re mod k+k*(t-1); if n=1 then write(1) else write(re); end.
Code mẫu của happyboy99x
#include <cstdio> #include <cmath> int main() { int n; scanf( "%d", &n ); if ( n == 1 ) printf( "1\n" ); else { int k = (int) ceil((sqrt(1+8*n)-1)/2); n -= (k-1)*k/2; int res = 1; for( int i = 2; i < k; ++i ) res = (res/i+i) * i; res = (res/k+1)*k; printf( "%d\n", res + (n-1)*k ); } return 0; }
Code mẫu của ladpro98
program nkdivseq; uses math; var f:array[1..100000] of longword; n,i,j,c:longint; val:longword; begin readln(n); i:=2; j:=1; f[1]:=1; while c<n do begin inc(j); if f[i-1] mod j <>0 then val:=j-(f[i-1] mod j) + f[i-1] else val:=f[i-1]+j; for c:=i to min(i+j-1,n) do begin f[c]:=val; inc(val,j); end; i:=i+j; end; write(f[n]); end.
Code mẫu của RR
var a:array[0..100111] of int64; start,n,i,j:longint; begin n:=0; for i:=1 to 1000 do begin if n>100000 then break; start:=(a[n] div i)*i; while start<=a[n] do inc(start,i); for j:=1 to i do begin inc(n); if n>100000 then break; a[n]:=start; start:=a[n]+i; end; end; read(n); writeln(a[n]); end.
Code mẫu của hieult
#include <stdio.h> main() { long n,t=0,i=0,a; scanf("%ld",&n); while(n!=0) { i++; for(int j=1;j<=i;j++) { if(n==0) break; else { if(j==1) { a=t%i; t=t+i-a; } else t+=i; n--; } } } printf("%ld",t); }
Code mẫu của ll931110
Program NKDIVSEQ; Const input = ''; output = ''; Var a: array[1..150000] of longint; n: longint; Procedure init; Var f: text; Begin Assign(f, input); Reset(f); Readln(f, n); Close(f); End; Procedure solve; Var pos,posi,val,i,k: longint; Begin pos:= 0; posi:= 0; val:= 0; For i:= 1 to 450 do Begin While posi < i do Begin inc(pos); inc(posi); val:= val + i; a[pos]:= val; End; posi:= 0; While (val mod (i + 1) <> 0) do dec(val); End; End; Procedure printresult; Var f: text; Begin Assign(f, output); Rewrite(f); Writeln(f, a[n]); Close(f); End; Begin init; solve; printresult; End.
Bình luận