3547 The Boss on Mars

#include <iostream>
#include <stdio.h>
#include <map>
using namespace std;

typedef long long LL;
const int MAXN = 10001;
const LL M = 1000000007;
int factor[10001],cnt;
LL n,res;

inline LL fix(LL val){
	return (val+M)%M;
}

inline LL pow4(LL val){
	val = fix(val*val);
	val = fix(val*val);
	return val;
}
LL cal(LL val){
	int i,a=2,b=3,c=5;
	LL t[4];
	t[0]=val,t[1]=val+1,t[2]=val*2+1,t[3]=3*val*val+3*val-1;
	for(i=0;i<4;i++){
		if(t[i]%a==0) t[i]/=a,a=1;
		if(t[i]%b==0) t[i]/=b,b=1;
		if(t[i]%c==0) t[i]/=c,c=1;
	}
	for(i=1;i<4;i++)
		t[0] = fix(t[0]*fix(t[i]));//妈的,这里以为t[i]之间相乘可以的。。竟然t[3]是两次方的,找了一晚上的伤不起啊
	return t[0];
}
void init(){
	LL tn = n;
	int i;
	for(i=2;i*i<=tn;i++){
		if(tn%i==0){
			factor[cnt++] = i;
			while(tn%i==0) tn/=i;
		}
	}
	if(tn!=1 ) factor[cnt++] = tn;
}

void solve(LL val,int idx,int flag,bool OK){
	
	if(OK) {
		LL now = cal(n/val)*pow4(val);
		now = fix(now);
		if(flag){
			res = fix(res - now);
		}else {
			res = fix(res + now);
		}
	}
	if(idx >= cnt) return;
	//solve(val*factor[idx],idx);
	solve(val*factor[idx],idx+1,flag^1,true);
	solve(val,idx+1,flag,false);
	
}

void run(){
	res = cal(n);
	cnt = 0;
	init();
	solve(1,0,0,false);
	//if(cnt)
	//res = fix(res+1);
	printf("%lld\n",res);
}

int main(){
	int T;
	cin>>T;
	while(T --){
		scanf("%lld",&n);
		run();
	}
}

/*
123
10
12
100
1000
10000
1
2
3
4
5
100000000
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值