ps:之前听过说long long的时间问题但是一直没有注意到过。直到遇见了他。。。。
这是一个瞎搞题点这里
思路:瞎搞
证明:int快
本着使劲优化的原则,,,加了4个优化。。但是在int数据类型其实这需要加2个多一点的优化就能过去。。。long long下需要加4个完整的优化才可以。
优化1:质数ans=(1+n)/2
优化2:因子只有2个质数组合
优化3:因子只有3个质数组合
优化4:因子只有4个质数组合
每个优化都有对应的ans遍不需要暴力来处理。。。。
但是在4种优化共同起作用时,
wuwuwu
本来早就可以水过
先附上瞎搞代码
int
#pragma GCC optimize(3,"Ofast","inline") //G++
#include
#define mem(a,x) memset(a,x,sizeof(a))
#define debug(x) cout << #x << ": " << x << endl;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fcout cout<
using namespace std;
typedef long long ll;
//======================================
namespace FastIO{
char print_f[105];void read() {}void print() {putchar('\n');}
template <typename T, typename... T2>
inline void read(T &x, T2 &... oth){x = 0;char ch = getchar();int f = 1;while (!isdigit(ch)){if (ch == '-')f *= -1;ch = getchar();}while (isdigit(ch)){x = x * 10 + ch - 48;ch = getchar();}x *= f;read(oth...);}
template <typename T, typename... T2>
inline void print(T x, T2... oth){int p3=-1;if(x<0) putchar('-'),x=-x;do{print_f[++p3] = x%10 + 48;}while(x/=10);while(p3>=0) putchar(print_f[p3--]);putchar(' ');print(oth...);}} // namespace FastIO
using FastIO::print;
using FastIO::read;
//======================================
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn = 1e6+5;
bool vis[maxn];
int vis1[maxn],vis2[maxn],vis3[maxn];
int prime[maxn],pos;
void oulasai(int n) //欧拉筛
{
for(int i=2;i<=n;i++)
{
if(!vis[i]) prime[++pos]=i;
for(int j=1;j<=pos;j++)
{
if(i*prime[j]>n) break;
vis[i*prime[j]]=true;
if(i%prime[j]==0) break;
}
}
vis[1]=1;
}
int cntt=0;
int solve(int n){
int st=sqrt(n);
for(int i=st;i>=1;i--){
cntt++;
if(n%i==0){
return (i+n/i)/2;
}
}
return 0;
}
int get(int a,int b,int c){
int x=0,y=0;
if(a+b*c<b+a*c) x=a,y=b*c;
else x=b,y=a*c;
if(x+y>c+a*b) x=c,y=a*b;
return (x+y)/2;
}
int get2(int a,int b,int c,int d){
int arr[4]={a,b,c,d};
vector<int>v;
for(int i=0;i<1<<4;i++){
int res=1;
for(int j=0;j<4;j++){
if(i>>j&1) res*=arr[j];
}
v.push_back(res);
}
sort(v.begin(),v.end());
return (v[7]+v[8])/2;
}
int res[maxn];
main() {
#ifndef ONLINE_JUDGE
freopen("H:\\code\\in.in", "r", stdin);
freopen("H:\\code\\out.out", "w", stdout);
clock_t c1 = clock();
#endif
//**************************************
oulasai(1000002);
for(int i=1;i<=pos;i++){
for(int j=1;j<=pos&&1ll*prime[i]*prime[j]<=1000000;j++){
if(1ll*prime[i]*prime[j]<=1000000) vis1[prime[i]*prime[j]]=(prime[i]+prime[j])/2;
}
}
for(int i=1;i<=pos;i++){
for(int j=i;j<=pos&&1ll*prime[i]*prime[j]<=1000000;j++){
for(int k=j;k<=pos&&1ll*prime[i]*prime[j]*prime[k]<=1000000;k++)
if(1ll*prime[i]*prime[j]*prime[k]<=1000000) vis2[prime[i]*prime[j]*prime[k]]=get(prime[i],prime[j],prime[k]);
}
}
for(int i=1;i<=pos;i++){
for(int j=i;j<=pos&&1ll*prime[i]*prime[j]<=1000000;j++){
for(int k=j;k<=pos&&1ll*prime[i]*prime[j]*prime[k]<=1000000;k++)
for(int l=k;l<=pos&&1ll*prime[i]*prime[j]*prime[k]*prime[l]<=1000000;l++)
if(1ll*prime[i]*prime[j]*prime[k]*prime[l]<=1000000) vis3[prime[i]*prime[j]*prime[k]*prime[l]]=get2(prime[i],prime[j],prime[k],prime[l]);
}
}
int ans=0;
for(int i=1;i<=1000000;i++){
if(!vis[i]) ans=ans+(1+i)/2;
else if(vis1[i]) ans=ans+vis1[i];
else if(vis2[i]) ans=ans+vis2[i];
else if(vis3[i]) ans=ans+vis3[i];
else ans=ans+solve(i);
ans%=mod;
res[i]=ans;
}
int T;
read(T);
while(T--){
int n;
read(n);
print(res[n]);
}
//**************************************
#ifndef ONLINE_JUDGE
cerr << "Time:" << clock() - c1 << "ms" << endl;
#endif
return 0;
}
long long
#pragma GCC optimize(3,"Ofast","inline") //G++
#include
#define mem(a,x) memset(a,x,sizeof(a))
#define debug(x) cout << #x << ": " << x << endl;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fcout cout<
using namespace std;
typedef long long ll;
//======================================
namespace FastIO{
char print_f[105];void read() {}void print() {putchar('\n');}
template <typename T, typename... T2>
inline void read(T &x, T2 &... oth){x = 0;char ch = getchar();ll f = 1;while (!isdigit(ch)){if (ch == '-')f *= -1;ch = getchar();}while (isdigit(ch)){x = x * 10 + ch - 48;ch = getchar();}x *= f;read(oth...);}
template <typename T, typename... T2>
inline void print(T x, T2... oth){ll p3=-1;if(x<0) putchar('-'),x=-x;do{print_f[++p3] = x%10 + 48;}while(x/=10);while(p3>=0) putchar(print_f[p3--]);putchar(' ');print(oth...);}} // namespace FastIO
using FastIO::print;
using FastIO::read;
//======================================
typedef pair<ll,ll> pii;
const ll inf=0x3f3f3f3f;
const ll mod=1e9+7;
const ll maxn = 1e6+5;
bool vis[maxn];
ll vis1[maxn],vis2[maxn],vis3[maxn];
ll prime[maxn],pos;
void oulasai(ll n) //欧拉筛
{
for(ll i=2;i<=n;i++)
{
if(!vis[i]) prime[++pos]=i;
for(ll j=1;j<=pos;j++)
{
if(i*prime[j]>n) break;
vis[i*prime[j]]=true;
if(i%prime[j]==0) break;
}
}
vis[1]=1;
}
int cntt=0;
ll solve(ll n){
ll st=sqrt(n);
for(ll i=st;i>=1;i--){
cntt++;
if(n%i==0){
return (i+n/i)/2;
}
}
return 0;
}
ll get(ll a,ll b,ll c){
ll x=0,y=0;
if(a+b*c<b+a*c) x=a,y=b*c;
else x=b,y=a*c;
if(x+y>c+a*b) x=c,y=a*b;
return (x+y)/2;
}
ll get2(ll a,ll b,ll c,ll d){
ll arr[4]={a,b,c,d};
vector<ll>v;
for(ll i=0;i<1<<4;i++){
ll res=1;
for(ll j=0;j<4;j++){
if(i>>j&1) res*=arr[j];
}
v.push_back(res);
}
sort(v.begin(),v.end());
return (v[7]+v[8])/2;
}
ll res[maxn];
main() {
#ifndef ONLINE_JUDGE
freopen("H:\\code\\in.in", "r", stdin);
freopen("H:\\code\\out.out", "w", stdout);
clock_t c1 = clock();
#endif
//**************************************
oulasai(1000002);
for(ll i=1;i<=pos;i++){
for(ll j=1;j<=pos&&prime[i]*prime[j]<=1000000;j++){
if(prime[i]*prime[j]<=1000000) vis1[prime[i]*prime[j]]=(prime[i]+prime[j])/2;
}
}
for(ll i=1;i<=pos;i++){
for(ll j=i;j<=pos&&prime[i]*prime[j]<=1000000;j++){
for(ll k=j;k<=pos&&prime[i]*prime[j]*prime[k]<=1000000;k++)
if(prime[i]*prime[j]*prime[k]<=1000000) vis2[prime[i]*prime[j]*prime[k]]=get(prime[i],prime[j],prime[k]);
}
}
for(ll i=1;i<=pos;i++){
for(ll j=i;j<=pos&&prime[i]*prime[j]<=1000000;j++){
for(ll k=j;k<=pos&&prime[i]*prime[j]*prime[k]<=1000000;k++)
for(ll l=k;l<=pos&&prime[i]*prime[j]*prime[k]*prime[l]<=1000000;l++)
if(prime[i]*prime[j]*prime[k]*prime[l]<=1000000) vis3[prime[i]*prime[j]*prime[k]*prime[l]]=get2(prime[i],prime[j],prime[k],prime[l]);
}
}
ll ans=0;
for(ll i=1;i<=1000000;i++){
if(!vis[i]) ans=ans+(1+i)/2;
else if(vis1[i]) ans=ans+vis1[i];
else if(vis2[i]) ans=ans+vis2[i];
else if(vis3[i]) ans=ans+vis3[i];
else ans=ans+solve(i);
ans%=mod;
res[i]=ans;
}
ll T;
read(T);
while(T--){
ll n;
read(n);
print(res[n]);
}
//**************************************
#ifndef ONLINE_JUDGE
cerr << "Time:" << clock() - c1 << "ms" << endl;
#endif
return 0;
}