What does Euler seem to be more troublesome than this???
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <vector>5 6 using namespacestd;7typedefLong Longll;8 9 ll Solve (ll a,ll N) {TenVector<ll>v; One for(LL i =2; I*i <= N; i + +) {//Prime number Decomposition A if(n% i = =0){ - V.push_back (i); - while(n%i = =0) n/=i; the } - } - if(N >1) V.push_back (n); - //there are several factors, which are used in binary notation +ll sum =0, tmp,cnt; - for(LL i =1; I < (1<<v.size ()); i + +){ +CNT =0; ATMP =1; at for(LL j =0; J < V.size (); J + +){ - if(I & (1<<j)) { -TMP *= V[J];//2 3; 6 -cnt++; - } - } in if(CNT &1) sum + = a/tmp;//allowance, sum means that there are several numbers in 1-a and n is not coprime - ElseSum-= A/tmp; to } + returnAsum; - } the * intMain () { $ intT;Panax Notoginsengscanf"%d",&T); - for(intCAS =1; CAS <= T; CAS + +){ the ll A,b,n; +scanf"%lld%lld%lld",&a,&b,&n); Aprintf"Case #%d:%lld\n", Cas,solve (B,n)-Solve (A-1, N)); the } + return 0; -}
HDU 4135 co-prime (Prime decomposition allowance)