给定一个NxNxN的正方体,求出最多能选几个整数点。使得随意两点PQ不会使PQO共线。
F(k)
#include<iostream> #include<cmath> #include<algorithm> using namespace std; const int N=5e5; #define int long long int b[N+2], pm[N+2],tot=0; int n; int pow3(int x){ return x*x*x-1; } void init(){ b[1] = 1; for (long long i = 2; i < N; i++) { if (b[i]) continue; pm[++tot] = i; for (long long j = i * i; j < N; j += i) b[j] = 1; } } int count(long long num) { int ans = 0; for (int i = 1; i <=tot && pm[i] <= num; i++) { if (!b[num]) {ans++; break;} if (num % pm[i] == 0) { ans++; num /= pm[i]; if (num % pm[i] == 0) return -1; } } return ans; } long long cal(long long num) { int t = count(num); if (t == -1) return 0; if (t&1) return -pow3((n / 2 / num) * 2 + 1); else return pow3((n / 2 / num) * 2 + 1); } signed main(){ init(); int cas=0; while(cin>>n&&n){ long long ans = pow3(n + 1); for (long long i = 2; i <= n; i++) ans += cal(i); printf("Crystal %d: %lld\n", ++cas, ans); } }
标签:UVA11014,int,tot,long,ans,include,pm From: https://www.cnblogs.com/towboa/p/17347550.html