1
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 4e7 + 10;
bool vis[maxn];ll primes[maxn];
ll sum[maxn];
ll cnt;
int main()
{
for(ll i=2;i<maxn;i++)
{
if(!vis[i])
{
primes[++cnt]=i;
}
for(ll j=1;primes[j]<=maxn/i;j++)
{
vis[i*primes[j]]=1;
if(i%primes[j]==0) break;
}
}
for(ll i=1;i<=cnt;i++)
{
sum[i]=sum[i-1]+primes[i];
}
ll tt;cin>>tt;
while(tt--)
{
ll n;cin>>n;ll ans=0;
for(ll i=0;i<=cnt&&primes[i]<=n;i++)
{
ll x = n + sum[i];
ll pos = lower_bound(sum+1,sum+1+cnt,x)-sum;
if(sum[pos]==x) ans++;
}
cout<<ans<<"\n";
}
}
2
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1000010;
int primes[N], cnt;
bool st[N];
void init(int n)
{
memset(st, 0, sizeof st);
cnt = 0;
for (int i = 2; i <= n; i ++ )
{
if (!st[i]) primes[cnt ++ ] = i;
for (int j = 0; primes[j] * i <= n; j ++ )
{
st[i * primes[j]] = true;
if (i % primes[j] == 0) break;
}
}
}
int main()
{
int l, r;
int n;
cin>>n;
while (n--)
{
init(50000);
cin>>l>>r;
memset(st, 0, sizeof st);
for (int i = 0; i < cnt; i ++ )
{
LL p = primes[i];
for (LL j = max(p * 2, (l + p - 1) / p * p); j <= r; j += p)
st[j - l] = true;
}
cnt = 0;
for (int i = 0; i <= r - l; i ++ )
if (!st[i] && i + l >= 2)
primes[cnt ++ ] = i + l;
if (cnt < 2) puts("There are no adjacent primes.");
else
{
int minp = 0, maxp = 0;
for (int i = 0; i + 1 < cnt; i ++ )
{
int d = primes[i + 1] - primes[i];
if (d < primes[minp + 1] - primes[minp]) minp = i;
if (d > primes[maxp + 1] - primes[maxp]) maxp = i;
}
printf("%d,%d are closest, %d,%d are most distant.\n",
primes[minp], primes[minp + 1],
primes[maxp], primes[maxp + 1]);
}
}
return 0;
}
3
#include <bits/stdc++.h>
using namespace std;
const int N = 3e4+5;
int p[N],idx;
bool st[N];
int qsm(int a,int b){
int s=1;
while(b){
if(b&1)s=s*a;
a=a*a;
b>>=1;
}
return s;
}
void init(int n){
for(int i=2;i<=n;i++){
if(!st[i])p[idx++]=i;
for(int j=0;p[j]<=n/i;j++){
st[p[j]*i]=true;
if(i%p[j]==0)break;
}
}
}
int main(){
init(N-1);
int T;
scanf("%d",&T);
while(T--){
int k;
scanf("%d",&k);
int n=1;
while(k--){
int a,b;
scanf("%d%d",&a,&b);
n*=qsm(a,b);
}
n--;
vector<int>va,vb;
for(int i=2;i<=n/i;i++){
if(n%i==0)
{
int s = 0;
while (n % i == 0) n /= i, s ++ ;
if(s){
va.push_back(i);
vb.push_back(s);
}
}
}
if(n>1)va.push_back(n);
vb.push_back(1);
for(int i=va.size()-1;i>=0;i--){
printf("%d %d",va[i],vb[i]);
if(!i)printf("\n");
else printf(" ");
}
}
return 0;
}
4
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int t,x;
long long fact[N];
int main()
{
fact[0]=1;
for(int i=1;i<=20;i++)fact[i]=fact[i-1]*i;
cin>>t;
while(t--){
unordered_map<int,int> mp;
scanf("%d",&x);long long res=0;
for(int i=2;i*i<=x;i++){
while(x%i==0){
mp[i]++;x/=i;res++;
}
}
if(x>1) mp[x]++,res++;
printf("%d ",res);
res=fact[res];
for(auto k:mp){
int u=k.second;
res/=fact[u];
}
printf("%lld\n",res);
}
}