Editorial for Phép 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
#include <iostream> #include <algorithm> #include <cstdio> #define calc(a) ((a)/12+(a)/30-((a)/60)*2) using namespace std; int main() { int test; long long a,b; cin >> test; while (test--) { scanf("%lld%lld",&a,&b); printf("%lld\n",calc(b)-calc(a-1)); } return 0; }
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; typedef unsigned long long LL; #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 int main() { int tc; scanf("%d",&tc); while(tc--) { LL a, b; scanf("%llu%llu", &a, &b); /*int res = 0; fo(i,a,b) if((i%4==0&&i%6==0&&i%15!=0)||(i%4==0&&i%6!=0&&i%15==0)||(i%4!=0&&i%6==0&&i%15==0)) res++; printf("%d\n",res);*/ --a; printf("%llu\n", b/12-a/12 + b/30-a/30 - 2*(b/60-a/60)); } return 0; }
Code mẫu của ladpro98
program pbcdiv; uses math; const fi=''; var a,b,m,n,p:int64; t,i:longint; inp:text; function calc(i:longint):int64; var x,y:int64; begin if a mod i = 0 then x:=a else x:=i-(a mod i)+a; if b mod i =0 then y:=b else y:=b - (b mod i); exit((y-x) div i +1); end; begin assign(inp,fi); reset(inp); readln(inp,t); for i:=1 to t do begin readln(inp,a,b); m:=calc(60); n:=calc(12); p:=calc(30); writeln(n+p-m-m); end; close(inp); end.
Code mẫu của RR
#include <cstdio> long long cnt(long long a){ return a/30+a/12-a/60*2; } int main(){ int t;scanf("%d",&t); long long a,b; while (t--){ scanf("%lld%lld",&a,&b); printf("%lld\n",cnt(b)-cnt(a-1)); } return 0; }
Code mẫu của hieult
#include <cstdio> //#include <conio.h> long long xuly(long long n){ return n/12+n/30-(n/60)*2; } int main(){ int test; long long A,B; scanf("%d",&test); for(int itest = 1;itest<=test;itest++){ scanf("%lld %lld",&A,&B); printf("%lld\n",xuly(B)-xuly(A-1)); } // getch(); }
Code mẫu của skyvn97
#include<stdio.h> typedef unsigned long long ull; int t,c; ull a,b,x,y,z; int main(void) { scanf("%d",&t); for (c=1;c<=t;c=c+1) { scanf("%llu",&a); scanf("%llu",&b); x=b/12-(a-1)/12; y=b/30-(a-1)/30; z=b/60-(a-1)/60; printf("%llu\n",x+y-2*z); } return 0; }
Comments