Visible TreesTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2213    Accepted Submission(s): 908

Problem Description
There are many trees forming a m * n grid, the grid starts from (1,1). Farmer Sherlock is standing at (0,0) point. He wonders how many trees he can see.
If two trees and Sherlock are in one line, Farmer Sherlock can only see the tree nearest to him.
 
Input
The first line contains one integer t, represents the number of test cases. Then there are multiple test cases. For each test case there is one line containing two integers m and n(1 ≤ m, n ≤ 100000)
 
Output
For each test case output one line represents the number of trees Farmer Sherlock can see.
 
Sample Input
2
1 1
2 3
 
Sample Output
1
5
 
Source
 
其实感觉这个代码写搓了  但是确实是利用队列的一种方式  重点理解dfs容斥方式
传送门 http://www.cnblogs.com/hsd-/p/5008912.html
 
#include<bits/stdc++.h>
using namespace std;
__int64 n;
__int64 a,b;
__int64 slove( __int64 m,__int64 gg)
{
__int64 que[1000];
__int64 a[1000];
memset(que,0,sizeof(que));
memset(a,0,sizeof(a));
__int64 sum=0;
__int64 t=0;
__int64 ss=0;
for(__int64 i=2;i*i<=m;i++)
{
if(m%i==0)
{
que[ss++]=i;
while(m%i==0)
m=m/i;
}
}
if(m>1)
que[ss++]=m;
a[t++]=-1;
for(__int64 i=0;i<ss;i++)
{
int k=t;
for(__int64 j=0;j<k;j++)
{
a[t++]=que[i]*a[j]*(-1);
}
}
for(__int64 i=1;i<t;i++)
sum=sum+gg/a[i];
return sum;
}
int main()
{
while(scanf("%I64d",&n)!=EOF)
{
for(__int64 i=1;i<=n;i++)
{
__int64 re=0;
scanf("%I64d %I64d",&a,&b);
for(__int64 j=1;j<=a;j++)
re+=slove(j,b);
printf("%I64d\n",a*b-re);
}
}
return 0;
}
 
 
 

最新文章

  1. hibernate学习(7)——HQL查询
  2. Linux命令小结:crontab/netstat/iostat/sar
  3. POJ - 1107 W&#39;s Cipher
  4. Fragment 切换问题
  5. Rolling Cursor Invalidations with DBMS_STATS.AUTO_INVALIDATE (文档 ID 557661.1)
  6. Linux中的svn客户端RabbitVCS-2
  7. MySQL架构优化实战系列2:主从复制同步与查询性能调优
  8. 性能测试分享:jmeter性能监控(一)
  9. 606. Construct String from Binary Tree
  10. 数据结构与算法 —— 链表linked list(02)
  11. 一句python代码搭建FTP服务
  12. java持有对象-集合类
  13. java框架之SpringBoot(14)-任务
  14. 微信出现BUG,发送“ 两位数字+15个句号 ”,双方系统会卡崩……
  15. Spark 分布式调试工具
  16. 在hadoop运行tensor flow
  17. [漏洞复现]CVE-2018-4887 Flash 0day
  18. UVALive-3972 March of the Penguins (最大流:节点容量)
  19. CUBE,ROLLUP 和 GROUPING
  20. oralce 查看执行计划

热门文章

  1. Java and SDK 环境变量设置
  2. Spring Cloud(六):Hystrix 监控数据聚合 Turbine【Finchley 版】
  3. Java学习 &#183; 初识 面向对象基础二
  4. vs_code 快捷键
  5. 你真的了解JAVA里的String么
  6. 十六:The YARN Service Registry
  7. python3 bytes与hex_string之间的转换
  8. Thunder团队第三周 - Scrum会议5
  9. 学霸系统UI项目功能说明书 v1.0版本
  10. Gym - 100851F Froggy Ford kruskal