质因数分解
求出[1,a] 的和 减去[1,b] 的和
#include<bits/stdc++.h>
using namespace std;
#define fst first
#define sec second
#define sci(num) scanf("%d",&num)
#define scl(num) scanf("%lld",&num)
#define mem(a,b) memset(a,b,sizeof a)
#define cpy(a,b) memcopy(a,b,sizeof b)
typedef long long LL;
typedef pair<int,int> P;
const int MAX_N = 510;
const int MAX_M = 10000;
const int MAX_P = 1e6 + 100;
bool notprime[MAX_P];
int primes[MAX_P],cnt;
void init() {
cnt = 0;
for (int i =2 ;i < MAX_P;i++) {
if (!notprime[i]) {
primes[cnt++] = i;
for (int j = i + i;j < MAX_P;j += i) {
notprime[j] = true;
}
}
}
}
LL cond(LL a) {
LL cp = 1;
for (int i = 0;i < cnt && primes[i] < a;i++) {
if (a % primes[i] == 0) {
int loc = 0;
while (a % primes[i] == 0 && a != 1) {
a = a / primes[i];
loc++;
}
cp *= (1 + loc);
}
}
if (a > 1) cp *= 2;
return cp;
}
int main() {
init();
int T;sci(T);
for (int cs = 1;cs <= T;cs++) {
LL a,b;
scl(a); scl(b);
LL ans = 0;
if (b * b < a) {
int c2 = 0;
for (LL i = 1;i < b;i++) {
if ( a % i == 0) c2++;
}
ans = cond(a) / 2- c2;
}
printf("Case %d: %lld\n",cs,ans);
}
return 0;
}