"BZOJ3629" "JLOI2014" smart Stef DFS Prime sieve

Source: Internet
Author: User

Link:
#include <stdio.h>int main(){    puts("转载请注明出处[vmurder]谢谢");    puts("网址:blog.csdn.net/vmurder/article/details/44698555");}
Exercises

We find that by decomposing a number into a factorization, we can then calculate the approximate number of these numbers according to the number of each mass factor. So we can violently dismantle each number, the root-square time complexity decomposition.
is to enumerate how much it is used for each prime number, and then the count is removed and the next layer is deep.

Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 50100using namespace STD;intprime[n],cnt;BOOLVis[n];voidShakeintN) {intI,j,k; for(i=2; i<=n;i++) {if(!vis[i]) prime[++cnt]=i; for(j=1; j<=cnt&&i*prime[j]<=n;j++) {vis[i*prime[j]]=1;if(i%prime[j]==0) Break; }    }}BOOLCheckintx) {BOOLflag=0; for(intI=1;(Long Long) prime[i]*prime[i]<=x;i++)if(x%prime[i]==0)return 0;return 1;}intAns[n],num;voidDfsLong LongNowintRemain,intT) {if(remain==1) {Ans[++num]=now;return;}if(remain==2)return;if(remain-1>=prime[t]&&check (remain-1)) ans[++num]=now* (remain-1); for(intI=t; (Long Long) {prime[i]*prime[i]<=remain;i++) {Long Longsum=prime[i]+1, X=prime[i]; while(Sum<=remain) {if(remain%sum==0) DFS (now*x,remain/sum,i+1);        X*=prime[i],sum+=x; }    }}intNintMain () {//Freopen ("Test.in", "R", stdin);Shake50000); while(scanf("%d", &n)!=eof) {num=0; Dfs1N1); Sort (ans+1, ans+num+1), n=0; for(intI=1; i<=num;i++)if(ans[i]!=ans[i-1]) ans[++n]=ans[i];printf("%d\n", n);if(n>=1)printf("%d", ans[1]); for(intI=2; i<=n;i++)printf("%d", Ans[i]);if(num)puts(""); }return 0;}

"BZOJ3629" "JLOI2014" smart Stef DFS Prime sieve

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.