题解:这道题要从n的角度来考虑i和j。

n可以表示为n=a1^p1*a2^p2*a3^p3......。n=lcm(i,j),那么质因子a1^p1,a1可以在i或者j中,并且p1=max(a1i,a1j)即pi为i中ai和j中ai的最大值。假设a1在i中,对于质因子a1,b中有[0,p1],一共有p1+1中选择。

a1在j中同理,a也有p1+1中选择。所以一共有2(p1+1)-1种情况。为什么要减去1呢?如果i中有p1个a1,b中也有p1个a1,这种情况我们算了两次。所以要减去1。然后累乘。这样算出来我们可以得到(i,j)和(j,i)的总数目。

所以应该除以2,如果i和j相等呢?我们除以2,把(i=n,j=n)这种情况除去了,所以应该再加1.

code:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const ll N = 1E6 + ;
const ll MAX = 1e7;
ll pre[N];
bool prime[MAX+];
ll pos = ;
void inint(){
prime[] = ;
for (ll i = ; i <= MAX; i++) {
if (!prime[i]) pre[++pos] = i;
for (ll j = ; j <= pos && i * pre[j] <= MAX; j++) {
prime[i * pre[j]] = ;
if (i % pre[j] == ) break;
}
}
}
void solve(ll time){
ll n;
scanf("%lld",&n);
ll n1 = n;
ll ans=;
for (ll i = ; i <= pos; i++) {
if (pre[i] > n1) break;
if (n1 % pre[i] == ){
ll p=;
while (n1 % pre[i] == ) {
n1 /= pre[i];p++;
}
ans*=((ll)+*p);
}
}
if (n1 != ) ans*=(ll);
printf("Case %d: %lld\n",time,ans/+(ll));
}
int main(){
inint();
int t;
scanf("%d",&t);
for(int i=;i<=t;i++) solve(i);
return ;
}

最新文章

  1. [bzoj2653][middle] (二分 + 主席树)
  2. MyBatis:统计数量
  3. 网易云音乐PC端刷曲快捷键
  4. 不能从const char *转换为LPCWSTR
  5. 【温故知新】C#委托delegate
  6. Codevs No.1163 访问艺术馆
  7. Illegal pattern character &#39;i&#39; 解决问题
  8. 20160314 Request 和Response
  9. django开发框架之jumpserver
  10. linux 开启防火墙操作
  11. 【Storm】Storm实战之频繁二项集挖掘
  12. cocos2d 从v1.x升级到v2.x需要注意的几个地方
  13. MySQL 基础知识梳理学习(一)----系统数据库
  14. centos下 telnet访问百度
  15. PLSQL安装、PLSQL汉化、激活
  16. 记一次oracle数据库复制过程
  17. select实现简单TCP通信(ubuntu 18.04)
  18. Slurm任务调度系统部署和测试(源码)(1)
  19. js实现文字超出部分用省略号代替实例代码
  20. CSS3 转换

热门文章

  1. CF1324F Maximum White Subtree 题解
  2. 报错:Error instantiating class com.liwen.mybatis.bean.Employee with invalid types () or values ().
  3. Building Applications with Force.com and VisualForce(Dev401)(十四):Implementing Business Processes:Auditing Processes
  4. ArrayList的传值问题
  5. prometheus远程写参数优化
  6. 在Fedora中安装OpenCV-Python | 二
  7. NeurIPS审稿引发吐槽大会,落选者把荒唐意见怼了个遍:“我谢谢你们了”
  8. coding++:SpringBoot-事务注解详解
  9. git本地库中配置多个sshkey
  10. 1078 Hashing (25分)