Editorial for Dãy chia hết
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
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.
Comments