Friends number NBUT - 1223 (暴力打表)
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.
//对5000000之内的每个数的所有因子暴力打表求和竟然不会超时,我擦。。。很强
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include <ctype.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std;
typedef long long ll;
const int maxn=11000;
const int INF=0x3f3f3f3f;
int f[5000010];
int xA[200],xB[200];
int main()
{
for(int i=1; i<=5000000; i++)//暴力打表,把每个数的所以因子的和求出来
{
int xsk=i+i;
while(xsk<=5000000)
{
f[xsk]+=i;//f函数存储的是每个数所以因子的和
xsk+=i;
}
}
int sum=0;
for(int i=1; i<=5000000; i++)
{
int A=i,B=f[i];
if(B>A&&B<5000000&&f[B]==i)
{
xA[sum]=A;
xB[sum]=B;
sum++;
}
}
int L,R;
while(~scanf("%d%d",&L,&R))
{
int ans=0;
for(int i=0; i<sum; i++)
{
if(xA[i]>=L&&xA[i]<=R&&xB[i]>=L&&xB[i]<=R) ans++;
}
printf("%d\n",ans);
}
return 0;
}
Friends number NBUT - 1223 (暴力打表)的更多相关文章
- XTU OJ 1210 Happy Number (暴力+打表)
Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number ...
- NBUT 1223 Friends number 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Paula and Tai are couple. There are many stories betwee ...
- HDU 5179 beautiful number (数位dp / 暴力打表 / dfs)
beautiful number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- HDU 1216 Assistance Required(暴力打表)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1216 Assistance Required Time Limit: 2000/1000 MS (Ja ...
- ACM/ICPC 之 暴力打表(求解欧拉回路)-编码(POJ1780)
///找到一个数字序列包含所有n位数(连续)一次且仅一次 ///暴力打表 ///Time:141Ms Memory:2260K #include<iostream> #include< ...
- HDU 1012 u Calculate e【暴力打表,水】
u Calculate e Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- Codeforces 914 C 数位DP+暴力打表+思维
题意 给出一个二进制数\(n\),每次操作可以将一个整数\(x\)简化为\(x\)的二进制表示中\(1\)的个数,如果一个数简化为\(1\)所需的最小次数为\(k\),将这个数叫做特殊的数, 问从\( ...
- 暴力打表之hdu 2089
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 有两种方法: 1.数位DP算法 2.暴力打表——真是个好法子!!! 接下来是注意点: 1.一般这 ...
随机推荐
- POJ 2456 Aggressive cows ( 二分搜索)
题目链接 Description Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The ...
- github: Permission denied (publickey). 问题解决方法
部署服务器过程中想clone自己github中的库,结果出现Permission denied (publickey).的错误,解决方法是添加服务器公钥到github的settings->SSH ...
- idea如何搭建springmvc4
1.推荐大牛博客 此操作我操作了三次过后终于成功了,奉献大牛博客连接:做的非常详细到位,望各位采纳,推荐置顶. https://www.cnblogs.com/chenlinghong/p/83395 ...
- sqlserver 树形结构表查询 获取拼接结果
树形表结构如下 IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Test]') AND ty ...
- word 宏,脚本编程
'脚本方式新建word 再新建文档,文档中输入字符串"你好" Dim wdapp As Word.Application Dim wddoc As Word.Document Se ...
- HDP-2.6.1安装
1.首先安装HDP的Ambari仓库文件到本机的/etc/yum.repos.d/ambari.repo路径下
- linux编程之文件操作
在linux下用文件描述符来表示设备文件盒普通文件,文件描述符是一个整型的数据,所有对文件的操作都是通过文件描述符来实现的. 文件描述符是文件系统中连接用户空间和内核空间的枢纽,当我们打开一个或者创建 ...
- dev_cpu_dead
Kernel: 4.12.6 每个cpu都有自己的softnet_data结构,用来处理数据包接收,但是当softnet_data所在cpu无法工作时,即CPUHP_NET_DEV_DEAD状态,就需 ...
- Windows 10又现新Bug,24核心竟卡成蜗牛
Windows 10又现新Bug,24核心竟卡成蜗牛 https://news.cnblogs.com/n/573996/
- C#中执行批处理文件(.bat),执行数据库相关操作
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...