11417 - GCD
Problem A
GCD
Input: Standard Input
Output: Standard Output
Given the value of N, you will have to find the value of G. The definition of G is given below:
|
|
Here GCD(i,j) means the greatest common divisor of integer i and integer j.
For those who have trouble understanding summation notation, the meaning of G is given in the following code:
|
G=0; for(i=1;i<N;i++) for(j=i+1;j<=N;j++) { G+=GCD(i,j); } /*Here GCD() is a function that finds the greatest common divisor of the two input numbers*/ |
Input
The input file contains at most 100 lines of inputs. Each line contains an integer N (1<N<501). The meaning of N is given in the problem statement. Input is terminated by a line containing a single zero. This zero should not be processed.
Output
For each line of input produce one line of output. This line contains the value of G for corresponding N.
Sample Input Output for Sample Input
|
10 100 500 0
|
67 13015 442011 |
#include<stdio.h>
int gcd(int a, int b)
{
if(!b) return a;
return gcd(b,a%b);
}
int main()
{
int n;
while (scanf("%d",&n)&&n)
{
int g=0,i,j;
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
g+=gcd(j,i);
printf("%d\n",g);
}
return 0;
}
11417 - GCD的更多相关文章
- uva 11417 - GCD
GCDInput: Standard Input Output: Standard Output Given the value of N, you will have to find the val ...
- Zerojudge解题经验交流
题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...
- Objective-C三种定时器CADisplayLink / NSTimer / GCD的使用
OC中的三种定时器:CADisplayLink.NSTimer.GCD 我们先来看看CADiskplayLink, 点进头文件里面看看, 用注释来说明下 @interface CADisplayLin ...
- iOS 多线程之GCD的使用
在iOS开发中,遇到耗时操作,我们经常用到多线程技术.Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法,只需定义想要执行的任务,然后添加到适当的调度队列 ...
- 【swift】BlockOperation和GCD实用代码块
//BlockOperation // // ViewController.swift import UIKit class ViewController: UIViewController { @I ...
- 修改版: 小伙,多线程(GCD)看我就够了,骗你没好处!
多线程(英语:multithreading),是指从软件或者硬件上实现多个线程并发执行的技术.具有多线程能力的计算机因有硬件支持而能够在同一时间执行多于一个线程,进而提升整体处理性能.具有这种能力的系 ...
- GCD的相关函数使用
GCD 是iOS多线程实现方案之一,非常常用 英文翻译过来就是伟大的中枢调度器,也有人戏称为是牛逼的中枢调度器 是苹果公司为多核的并行运算提出的解决方案 1.一次性函数 dispatch_once 顾 ...
- hdu1695 GCD(莫比乌斯反演)
题意:求(1,b)区间和(1,d)区间里面gcd(x, y) = k的数的对数(1<=x<=b , 1<= y <= d). 知识点: 莫比乌斯反演/*12*/ 线性筛求莫比乌 ...
- hdu2588 GCD (欧拉函数)
GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数. (文末有题) 知 ...
随机推荐
- ASP .Net Core 使用 Dapper 轻型ORM框架
一:优势 1,Dapper是一个轻型的ORM类.代码就一个SqlMapper.cs文件,编译后就40K的一个很小的Dll. 2,Dapper很快.Dapper的速度接近与IDataReader,取列表 ...
- Java之线程的生命周期
在Java中,线程有5中不同状态,分别是:新建(New).就绪(Runable).运行(Running).阻塞(Blocked)和死亡(Dead).它们之间的转换图如下: 上图有一个例外,调用yiel ...
- web安全记录
前端 CSRF 跨站请求伪造 客户端添加伪随机数,后台验证 验证码 中间人攻击 SSL证书加密 xss(跨站脚本攻击)漏洞,微软的字符检验(自动) 文本展示编码处理 做标签展示的文本尤其过滤脚本 Co ...
- Oracle EBS-SQL (PO-4):检查采购订单明细.sql
SELECT PHA.SEGMENT1 订单号, pha.approved_flag 批准状态, pha.closed_code 订 ...
- JavaScript学习之—prototype
一.利用prototype扩展String方法,去除字符前后空格: String.prototype.trim = function String$trim() { if (arguments.len ...
- VirtualBox详细教程
转自:http://bbs.kafan.cn/thread-358294-1-1.html 1.Sun xVM VirtualBox简介 VirtualBox官方网站:http://www.virtu ...
- javascript小知识1 this的用法
函数的应用: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- 探求C#.Net中ArrayList与Array的区别 【转】
ArrayList与Array的区别概述 ArrayList 是数组的复杂版本.ArrayList 类提供在大多数 Collections 类中提供但不在 Array 类中提供的一些功能.例如 ...
- 黑马程序员_高新技术之javaBean,注解,类加载器
----------- android培训.java培训.java学习型技术博客.期待与您交流! ---------- 第一部分 javaBean 一,由内省引出javaBean 1,内省: 内省对应 ...
- Java复习第一天---Javascript的基本知识点
1.HelloWord: 2.基础语法: 3.嵌入HTML 借助window.onload事件在整个窗体载入完毕之后运行程序代码 4.事件驱动: 5.DOM操作 5.1 查找元素节点 5.1.1 依据 ...
