HOJ 1015 Nearly prime numbers

ExpandedBlockStart.gif代碼
//Nearly?prime?number?is?an?integer?positive?number?for?which?it?is?possible?
//to?find?such?primes?P1?and?P2?that?given?number?is?equal?to?P1*P2.
#include?<stdio.h>
#include?
<stdlib.h>
#include?
<math.h>

//decide?n?whither?is?a?nearly?prime?number?or?not,
//is?then?return?true,or?return?false.
bool?isNPN(int?n);
//decide?n?whither?is?a?prime?number?or?not,
//is?then?return?true,or?return?false.
bool?isPrime(int?n);

int?main()
{
????
int?input[50000];????
????
int?num;
????
????
//input
????scanf("%d",?&num);
????
for?(int?i=0;?i<num;?i++)
????{
????????scanf(
"%d",?&input[i]);
????}

????
//start?resolve?the?problem?here
????for?(int?i=0;?i<num;?i++)
????{
????????
if?(isNPN(input[i]))
????????{
????????????printf(
"Yes\n");
????????}
????????
else
????????{
????????????printf(
"No\n");
????????}
????}

????
return?0;
}

bool?isNPN(int?n)
{
????
int?m?=?(int)sqrt((double)n)?+?1;

????
if?(n%2==0?&&?isPrime(n/2))
????{
????????
return?true;
????}
????
for?(int?i=3;?i<m;?i+=2)
????{
????????
if?(n%i?==?0?&&?isPrime(i))
????????{
????????????
if?(isPrime(n/i))
????????????{
????????????????
return?true;
????????????}
????????}
????}
????
return?false;
}

bool?isPrime(int?n)
{
????
int?m?=?(int)sqrt((double)n)?+?1;
????
????
if?(n?==?2)
????{
????????
return?true;
????}
????
if?(n%2?==?0)
????{
????????
return?false;
????}
????
for(int?i=3;?i<m;?i+=2)
????{
????????
if?(n%i==0)
????????{
????????????
return?false;
????????}
????}
????
return?true;
}

?

轉載于:https://www.cnblogs.com/XiaoS/archive/2010/04/17/1714196.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/276098.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/276098.shtml
英文地址,請注明出處:http://en.pswp.cn/news/276098.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

「前端工程化」該怎么理解?

大家好&#xff0c;我是若川。今天分享一篇「前端工程化」的好文。非廣告&#xff0c;請放心閱讀。可點擊下方卡片關注我&#xff0c;或者查看系列文章。今天發文比較晚&#xff0c;以往都是定時早上7:30發文&#xff0c;也不知道是不是有點早。一.什么是前端工程&#xff1f;一…

axure文本框值相加_Axure教程:計數文本域實現

原標題&#xff1a;Axure教程&#xff1a;計數文本域實現制定UI規范時&#xff0c;遇到實現“限制字數的文本域”的交互問題&#xff0c;即當用戶輸入的字數長度超過限制要求&#xff0c;如何只保留規定長度的文本&#xff1f;效果如下&#xff1a;我們知道【Number】類型的文本…

figma下載_Figma和ProtoPie中的原型制作,比較

figma下載第1部分 (Part 1) Prototyping has never had such a high profile with a whole host of tools that now give you varying ability to realize your designs beyond their static UI and into a working usable thing. It’s fair to say that prototyping within t…

拗口翻譯

I find many times people use temporary tables because they learned in other databases that joining too many tables in a single query is a ?bad thing?. This is a practice that must be unlearned for Oracle development. Rather then trying to out‐smart the …

javascript 手機手勢動作touch觸屏原理分析

轉載鏈接&#xff1a;http://www.lvtao.net/web/220.html $(function(){document.getElementById("moveId").addEventListener(touchstart, touchStart);document.getElementById("moveId").addEventListener(touchmove, touchMove);document.getElementBy…

并發工具類(四)線程間的交換數據 Exchanger

前言JDK中為了處理線程之間的同步問題&#xff0c;除了提供鎖機制之外&#xff0c;還提供了幾個非常有用的并發工具類&#xff1a;CountDownLatch、CyclicBarrier、Semphore、Exchanger、Phaser&#xff1b;??CountDownLatch、CyclicBarrier、Semphore、Phaser 這四個工具類提…

「前端組件化」該怎么理解?

大家好&#xff0c;我是若川。今天分享一篇關于「前端組件化」的好文。歡迎點擊下方卡片關注我。以下是正文~這里我們一起來學習前端組件化的知識&#xff0c;而組件化在前端架構里面是最重要的一個部分。講到前端架構&#xff0c;其實前端架構中最熱門的就有兩個話題&#xff…

大屏設計的視覺統一_視覺設計中的統一

大屏設計的視覺統一視覺設計的統一性是什么&#xff1f; (What is unity in visual design?) The concept of unity in visual design means a group of elements working together to create a greater whole. It means, as the clich goes: A whole that is greater than th…

l2范數求導_機器學習中的范數規則化之(一)L0、L1與L2范數

source: https://blog.csdn.net/zouxy09/article/details/24971995zouxy09qq.comhttp://blog.csdn.net/zouxy09今天我們聊聊機器學習中出現的非常頻繁的問題&#xff1a;過擬合與規則化。我們先簡單的來理解下常用的L0、L1、L2和核范數規則化。最后聊下規則化項參數的選擇問題。…

9.struts1.x中tiles框架的使用

在頁面直接使用titles標簽先引入標簽&#xff1a;<%taglib uri"http://struts.apache.org/tags-tiles" prefix"tiles" %> 將模板頁面要代替的內容用標簽占位&#xff1a;<tiles:insert attribute"content"></tiles:insert> 在…

Debian 9.6.0 + OpenMediaVault 4.x : U盤作系統盤時遇到的問題

前幾天在虛擬機試驗的時候還說裝到實機一般也沒什么問題&#xff0c;然后突然間想試試如果把 Debian9OMV 都放到U盤里會怎么樣。于是就折騰&#xff08;然后懵逼&#xff09; 先總結一下 寫入openmediavault官方的iso到U盤使用UNetbootin寫入Debian9的iso使用UltraISO的默認設置…

新浪微博、騰訊微博、QQ空間、人人網、豆瓣 一鍵分享API

轉載鏈接&#xff1a;http://www.bluesdream.com/blog/sina-tencent-renren-douban-share-a-key-api.html 新浪微博&#xff1a; http://service.weibo.com/share/share.php?url count表示是否顯示當前頁面被分享數量(1顯示)(可選&#xff0c;允許為空) &url將頁面地址轉…

跟著官方文檔能學懂React Hooks就怪了

大家好&#xff0c;我是若川。今天分享一篇關于「React Hooks」的好文。歡迎點擊下方卡片關注我。以下是正文~回想下你入門Hooks的過程&#xff0c;是不是經歷過&#xff1a;類比ClassComponent的生命周期&#xff0c;學習Hooks的執行時機慢慢熟練以后&#xff0c;發現Hooks的執…

origin圖上顯示數據標簽_Origin(Pro):寒假都結束了,這個圖還是不會畫?【數據繪圖】...

寒假前給大家分享了一個圖&#xff0c;大家要的教程來了。【數據繪圖】好圖分享&#xff1a;寒假&#xff1f;不存在的&#xff01;?mp.weixin.qq.com繪圖思路&#xff1a;左側起止時間&#xff1a;散點圖&#xff0c;交換XY坐標軸&#xff1b;中間的連線為Drop Lines&#xf…

可以激發設計靈感的音樂_建立靈感庫以激發您的創造力

可以激發設計靈感的音樂I often find a lot of inspiration from work I see while scrolling social media. Saving art or images that inspire you allows you to build a library of resources to draw from whenever you’re working on a project.在滾動社交媒體時&#…

CentOS服務器上部署 oracle10gr2

1、下載Centos系統 Linux 鏡像文件。 推薦使用 CentOS5.4&#xff0c;下載地址&#xff1a;http://isoredirect.centos.org/centos/5/isos/i386/ 。這個是 32 位的 Linux 系統鏡像安裝文件&#xff0c;進入下載頁面后&#xff0c;如果是 DVD 光盤安裝&#xff0c;可以僅…

回顧:中網通訊網絡公司CEO羅與曾作客新浪嘉賓聊天室

轉載鏈接&#xff1a;http://tech.sina.com.cn/it/w/2001-11-09/91253.shtml 回顧&#xff1a;中網通訊網絡公司CEO羅與曾作客新浪嘉賓聊天室 大家好&#xff01;   主持人 &#xff1a;各位網友&#xff0c;下午好&#xff0c;今天我們請到了中網通訊網絡公司首席執行官羅…

form——驗證器Validators

form表單最大的作用就是驗證功能了&#xff0c;通過cleaned_data清洗&#xff0c;我們可以獲取傳來的值&#xff0c;通過參數、驗證器、自定義驗證方法&#xff0c;我們可以做到很多的驗證。 驗證器可用于在不同類型的字段之間重用驗證邏輯。validators有自帶的驗證器&#xff…

若川知乎問答:做前端感覺很吃力怎么辦?

前些日&#xff0c;我發了一篇推文《做前端感到越來越吃力了&#xff01;怎么辦&#xff1f;》&#xff0c;雖然是推廣&#xff0c;但閱讀量卻很高&#xff0c;推廣標題我們大概率不能改&#xff0c;感覺騙了大家&#xff0c;掉粉挺多人。寫稿的人可能就是看到了知乎這個問答。…

惠新宸php教程_惠新宸:首位國人加入PHP語言官方開發組

PHP開發組終于有了國人參與。最近&#xff0c; Laruence(真名惠新宸)加入了PHP語言官方開發組。 做PHP的同學一定很熟悉他了&#xff0c;他的博客風雪之隅(https://www.laruence.com/)發表了很多PHP源代碼分析和擴展開發相關的文章。他使用PHP擴展開發的PHP框架Yaf&#xff0c;…