快速求朋友数(暂时还没有看懂)当模板用吧
来源:互联网 发布:win10多线程优化 编辑:程序博客网 时间:2024/05/16 01:28
Paula and Tai are couple. There are many stories between them. The day Paula left by airplane, Tai send one message to telephone 2200284, then, everything is changing… (The story in “the snow queen”).
After a long time, Tai tells Paula, the number 220 and 284 is a couple of friends number, as they are special, all divisors of 220’s sum is 284, and all divisors of 284’s sum is 220. Can you find out there are how many couples of friends number less than 10,000. Then, how about 100,000, 200,000 and so on.
The task for you is to find out there are how many couples of friends number in given closed interval [a,b]。
输入
There are several cases.
Each test case contains two positive integers a, b(1<= a <= b <=5,000,000).
Proceed to the end of file.
输出
For each test case, output the number of couples in the given range. The output of one test case occupied exactly one line.
样例输入
1 100
1 1000
样例输出
0
1
提示
6 is a number whose sum of all divisors is 6. 6 is not a friend number, these number is called Perfect Number.
朋友数就是;数字A的因子和等于数字B;数字B的因子和也等于数字A;
直接贴快速求朋友数的代码;;
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cstdlib>using namespace std;int a[5000005];int main(){ int i,j; memset(a,0,sizeof a); for(i=1;i<=500000;i++) { for(j=1;i*j<=500000;j++) { a[i*j]+=i; } } for(i=1;i<=500000;i++) a[i]-=i; int k=0; for(i=1;i<=500000;i++) { if(i==a[a[i]] && i!=a[i]) { if(i>a[i]) continue; printf("%d,",a[i]); k++; } } return 0;}
这个题目就是将到5百万的朋友数打表,然后在应该比较容易了吧;
- 快速求朋友数(暂时还没有看懂)当模板用吧
- 暂时还没有发现问题:)
- 快速求第n位卡特兰数模板
- 快速求素数模板
- 【求组合数模板】
- 求组合数模板
- 求组合数模板
- hulu2014笔试题,求朋友数
- 三层结构,暂时没看懂
- 信息管理器(还没有想到好得名字,暂时叫这个吧!)
- 快速二分求幂 模板
- 求组合数(模板)
- 求大组合数模板
- 一个有趣的程序-暂时没有看懂
- 求朋友
- 求N!最右位非0数模板
- 归并排序模板 && 求逆序数
- 树状数组求逆序数的模板
- 为团队成员分配TFS2012账户
- Spring声明式事务配置管理方法
- Java编程思想学习笔记(十一) 第12章 通过异常处理错误
- 【微框架】Maven +SpringBoot 集成 阿里大鱼 短信接口详解与Demo
- spring详解
- 快速求朋友数(暂时还没有看懂)当模板用吧
- 字符串最后一个单词的长度
- Git撤销Commit操作
- 一个测试博客
- 1016 水仙花数 V2
- UIBezierPath 赛贝尔曲线
- Android屏幕适配方案
- HIVE和HBASE区别
- 软件项目免坑指南