第一题给定一个大数,分解质因数,每个质因子的个数为e1,e2,e3,……em,

则结果为((1+2*e1)*(1+2*e2)……(1+2*em)+1)/2.

代码如下:

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. #include <iostream>
  5. #define M 10000005
  6. #define mod 1000000007
  7. #define ll unsigned long long
  8. using namespace std;
  9. ll prime[M/],cnt;
  10. bool f[M];
  11. void init()
  12. {
  13. int i,j;
  14. cnt=;
  15. for(i=;i<M;i++){
  16. if(!f[i]) prime[cnt++]=i;
  17. for(j=;j<cnt&&i*prime[j]<M;j++){
  18. f[i*prime[j]]=;
  19. if(i%prime[j]==) break;
  20. }
  21. }
  22. }
  23. ll solve(ll n)
  24. {
  25. ll ans=;
  26. for(ll i=;i<cnt&&(ll)prime[i]*prime[i]<=n;i++){
  27. if(n%prime[i]==){
  28. ll t=;
  29. n/=prime[i];
  30. while(n%prime[i]==){
  31. t++;
  32. n/=prime[i];
  33. }
  34. ans*=(ll)(+t*);
  35. }
  36. }
  37. if(n>) ans=*ans;
  38. return (ans+)/;
  39. }
  40. int main()
  41. {
  42. int t,ca=;
  43. ll n;
  44. init();
  45. scanf("%d",&t);
  46. while(t--){
  47. scanf("%llu",&n);
  48. printf("Case %d: %llu\n",++ca,solve(n));
  49. }
  50. return ;
  51. }

第二题给定一个数N,其质因子pi及个数ei给定,

则结果为(1+p1+p1^2+……+p1^ei+ei*p1^ei)*……*(1+pm+pm^2+……+pm^em+em*pm^em)+N.

代码如下:

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. #include <iostream>
  5. #define mod 1000000007
  6. #define ll long long
  7. using namespace std;
  8. ll Pow(ll a,int b)
  9. {
  10. ll ans=;
  11. while(b){
  12. if(b&) ans=(ans*a)%mod;
  13. b>>=;
  14. a=(a*a)%mod;
  15. }
  16. return ans;
  17. }
  18. ll sum(ll a,int b)
  19. {
  20. if(b==) return ;
  21. if(b&) return (+Pow(a,(b+)/))*sum(a,b/)%mod;
  22. else return ((+Pow(a,b/+))*sum(a,b/-)%mod+Pow(a,b/))%mod;
  23. }
  24. int main()
  25. {
  26. int t,ca=,n,p,e;
  27. scanf("%d",&t);
  28. while(t--){
  29. scanf("%d",&n);
  30. ll ans=,xx,num=;
  31. for(int i=;i<n;i++){
  32. scanf("%d%d",&p,&e);
  33. xx=Pow(p,e);
  34. num=(num*xx)%mod;
  35. xx=(xx*e)%mod;
  36. xx=(xx+sum(p,e))%mod;
  37. ans=(ans*xx)%mod;
  38. }
  39. printf("Case %d: %lld\n",++ca,(ans+num)%mod);
  40. }
  41. return ;
  42. }

light oj 1236 - Pairs Forming LCM & uva 12546 - LCM Pair Sum的更多相关文章

  1. Light oj 1236 - Pairs Forming LCM (约数的状压思想)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意很好懂,就是让你求lcm(i , j)的i与j的对数. 可以先预处理1e7以 ...

  2. LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS     Memor ...

  3. 1236 - Pairs Forming LCM

    1236 - Pairs Forming LCM   Find the result of the following code: long long pairsFormLCM( int n ) {  ...

  4. Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩

    题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...

  5. LightOJ 1236 - Pairs Forming LCM(素因子分解)

    B - Pairs Forming LCM Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  6. LightOJ - 1236 - Pairs Forming LCM(唯一分解定理)

    链接: https://vjudge.net/problem/LightOJ-1236 题意: Find the result of the following code: long long pai ...

  7. LightOj 1236 - Pairs Forming LCM (分解素因子,LCM )

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意:给你一个数n,求有多少对(i,  j)满足 LCM(i, j) = n, ...

  8. 1236 - Pairs Forming LCM -- LightOj1236 (LCM)

    http://lightoj.com/volume_showproblem.php?problem=1236 题目大意: 给你一个数n,让你求1到n之间的数(a,b && a<= ...

  9. LightOJ 1236 Pairs Forming LCM 合数分解

    题意:求所有小于等于n的,x,y&&lcm(x,y)==n的个数 分析:因为n是最小公倍数,所以x,y都是n的因子,而且满足这样的因子必须保证互质,由于n=1e14,所以最多大概在2^ ...

随机推荐

  1. spring cloud config 详解

    Spring Cloud 为开发人员提供了一系列的工具来快速构建分布式系统的通用模型 .例如:配置管理.服务发现.断路由.智能路由.微代理.控制总线.一次性Token.全局锁.决策竞选.分布式sess ...

  2. 【Python学习笔记】Coursera课程《Using Python to Access Web Data 》 密歇根大学 Charles Severance——Week2 Regular Expressions课堂笔记

    Coursera课程<Using Python to Access Web Data > 密歇根大学 Charles Severance Week2 Regular Expressions ...

  3. 【UOJ#164】清华集训2015V

    QwQzcysky真是菜死了,这是我刚上高一的时候坤爷在夏令营讲的,可是今天才切掉…… 想想也神奇,一个2016.11才学会线段树的菜鸡,夏令营的时候居然听过Segment-Tree-Beats? 所 ...

  4. 设计模式之笔记--单例模式(Singleton)

    单例模式(Singleton) 定义 单例模式(Singleton),保证一个类仅有一个实例,并提供一个访问它的全局访问点. 类图 描述 类Singleton的构造函数的修饰符为private,防止用 ...

  5. [How to] 使用Xib来创建view

    1.简介 代码库 正如之前博客介绍的,xib可定义页面的某个部分,特别当此部分区域的view集中并且还有一些相互关联性(如隐藏等)是i特别适合使用xib来进行封装. 本文为[How to]使用自定义c ...

  6. kivy安装

    >>> os.system('pip install kivy')Collecting kivy Downloading Kivy-1.9.1-cp27-none-win_amd64 ...

  7. [ Python ] 基本数据类型及属性(下篇)

    1. 基本数据类型 (1) list 列表     (2) tuple 元组     (3) dict 字典     (4) set 集合 2. list 列表方法 Python 内置的一种数据类型, ...

  8. mysql 5.1.7.17 zip安装 和 隔段时间服务不见了处理

    Mysql社区版下载地址:http://dev.mysql.com/downloads/mysql/ 因为我的系统版本是64,因此这里下载x64版本.下载完之后解压至D:\Dev\Mysql(即为my ...

  9. HDU-5351

    MZL's Border Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  10. 并发容器ConcurrentHashMap与synchronized联合使用达到线程安全

    http://blog.csdn.net/yansong_8686/article/details/50664338 map.put(KEY, map.get(KEY) + 1); 实际上并不是原子操 ...