HDU 4135 Co-Prime)
# Include <cstdio> # include <cstring> using namespace STD; typedef long ll; # define maxn 100int FAC [maxn], CNT; void gaoji (int x) // x prime factor decomposition {CNT = 0; For (INT I = 2; I * I <= x;) {If (X % I = 0) {FAC [CNT ++] = I; while (X % I = 0) x/= I;} if (I = 2) I ++; else I + = 2;} If (x> 1) FAC [CNT ++] = x;} ll solve (LL X) {ll res = 0; for (ll I = 1; I <(1 <CNT); ++ I) // binary compression {ll Mul = 1, BITs = 0; for (ll j = 0; j <CNT; ++ J) {If (I> J) & 1) {++ bits; mul * = FAC [J];} If (BITS & 1) RES + = x/MUL; else res-= x/MUL;} return X-res ;} void orz () {int T, CAS = 1, n; scanf ("% d", & T); While (t --) {ll A, B; scanf ("% i64d % i64d % d", & A, & B, & N); gaoji (n); LL ans = solve (B) -Solve (A-1); printf ("case # % d: % i64d \ n", CAS ++, ANS) ;}} int main () {orz (); return 0 ;}
Code Jun
HDU 4135 Co-Prime)