题解

139 条题解

  • 1
    @ 2023-06-07 18:36:41
    #include <bits/stdc++.h>
    using namespace std;
    int f(int n){
    int i,s=2;
    for(i=2;i<n;i++)
    if(n%i==0)
    s++;
    return s;
    }
    int main(){
    int k,i;
    cin>>k;
    for(i=1;i<=20000;i++){
    if(f(i)==k){
    cout<<i;
    break;
    }
    if(i==20000)
    cout<<"NO SOLUTION";
    }
    return 0;
    }
    
  • 0
    @ 2018-02-03 10:44:41

    #include<bits/stdc++.h>
    using namespace std;
    int f(int n){
    int i,s=0;
    for(i=1;i<=n;i++)
    if(n%i==0)
    s++;
    return s;
    }
    int main(){
    int i,k;
    cin>>k;
    for(i=1;i<=20000;i++){
    if(f(i)==k){
    cout<<i;
    break;
    }
    if(i==20000)
    cout<<"NO SOLUTION";
    }
    return 0;
    }

  • 0
    @ 2018-02-03 10:10:06

    #include <bits/stdc++.h>
    using namespace std;
    int f(int n){
    int i,s=2;
    for(i=2;i<n;i++)
    if(n%i==0)
    s++;
    return s;
    }
    int main(){
    int k,i;
    cin>>k;
    for(i=1;i<=20000;i++){
    if(f(i)==k){
    cout<<i;
    break;
    }
    if(i==20000)
    cout<<"NO SOLUTION";
    }
    return 0;
    }

  • 0
    @ 2017-10-03 15:18:12

    #include<iostream>
    #include<vector>
    #define lowbit(x) x&-x
    #define maxa 500000+100
    using namespace std;
    int f(int x)
    {
    int j;
    int ans = 0;
    for(j=1;j<=x/2;++j)
    if(x%j==0)
    ans++;
    return ans+1;
    }
    int main()
    {
    int k;
    cin>>k;
    int i = 1;
    while(f(i)!=k&&i<=20000)
    i++;
    if(i>20000)
    cout<<"NO SOLUTION"<<endl;
    else
    cout<<i<<endl;
    return 0;
    }

  • 0
    @ 2017-04-05 12:15:01
    #include <stdio.h>
    int main()
    {
        int n,i,j,count;
        scanf("%d",&n);
        for(i=1;i<=20000;i++)
        {
            count=0;
            for(j=1;j<=i;j++) if (i%j==0) count++;
            if (count==n) 
            {
                printf("%d",i);
                return 0;
            }
        }
        printf("NO SOLUTION");
        return 0;
    }
    
  • 0
    @ 2016-12-23 00:15:45

    水 总在半夜Ac题。。。我服自己
    ```c++
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    int main()
    {
    int n,c;
    scanf("%d",&n);
    for(int i=1;i <= 20000;i++)
    {
    c=0;
    for(int j=1;j <= i;j++)
    {
    if(i % j == 0) c++;

    }
    if(c==n) {printf("%d",i);return 0;}
    }
    printf("NO SOLUTION");
    return 0;
    }

  • 0
    @ 2016-10-26 12:35:07

    /*
    一道入门枚举水题了~
    看到超过2万就直接输出无解就知道直接枚举是可以的
    一共一万个数字
    在判断有多少个正因子的时候
    可以直接试到sqrt(x)也可以直接试到x(虽然慢了但是是可行的)
    主要要特殊判断一下
    如果x正好是一个完全平方数
    那么返回的数量就应该是tot*2-1(sqrt(x)不能算两次)
    如果不是的话自然就是sqrt(x)*2了
    这道是入门题了
    有个dfs加强版咯P1310推荐做一下~
    ```
    */
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;

    const int maxw=20000;
    int k;

    int work(int x)
    {
    int c=sqrt(x)+0.5;
    int tot=0;
    for(int i=1;i<=c;i++)
    if(x%i==0)
    tot++;
    if(c*c==x)
    return (tot<<1)-1;
    else
    return tot<<1;
    }

    int main()
    {
    cin>>k;
    for(int i=1;i<=maxw;i++)
    {
    if(work(i)==k)
    {
    cout<<i<<endl;
    return 0;
    }
    }
    cout<<"NO SOLUTION"<<endl;
    return 0;
    }
    ```
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #2: Accepted, time = 15 ms, mem = 560 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #6: Accepted, time = 15 ms, mem = 564 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 564 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 560 KiB, score = 10
    测试数据 #9: Accepted, time = 15 ms, mem = 560 KiB, score = 10
    Accepted, time = 45 ms, mem = 564 KiB, score = 100

  • 0
    @ 2016-08-16 21:49:51

    记录信息

    评测状态 Accepted
    题目 P1229 分解因式
    递交时间 2016-08-16 21:45:20
    代码语言 C++
    评测机 ShadowShore
    消耗时间 3261 ms
    消耗内存 560 KiB
    评测时间 2016-08-16 21:45:24

    评测结果

    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 556 KiB, score = 10

    测试数据 #1: Accepted, time = 687 ms, mem = 560 KiB, score = 10

    测试数据 #2: Accepted, time = 0 ms, mem = 560 KiB, score = 10

    测试数据 #3: Accepted, time = 31 ms, mem = 556 KiB, score = 10

    测试数据 #4: Accepted, time = 703 ms, mem = 556 KiB, score = 10

    测试数据 #5: Accepted, time = 15 ms, mem = 560 KiB, score = 10

    测试数据 #6: Accepted, time = 265 ms, mem = 560 KiB, score = 10

    测试数据 #7: Accepted, time = 421 ms, mem = 560 KiB, score = 10

    测试数据 #8: Accepted, time = 718 ms, mem = 556 KiB, score = 10

    测试数据 #9: Accepted, time = 421 ms, mem = 560 KiB, score = 10

    Accepted, time = 3261 ms, mem = 560 KiB, score = 100

    代码

    //水王万岁!!!@-@
    #include<iostream>
    using namespace std;
    int main()
    {
    int i,k;
    cin>>k;
    for(i=1;i<=20000;i++)
    {
    long long ans=0;
    for(int j=1;j<=i;j++)
    {
    if(i%j==0)
    ans++;
    }
    if(ans==k)
    {
    cout<<i;
    return 0;
    }
    }
    cout<<"NO SOLUTION";
    return 0;
    }

  • 0
    @ 2016-07-22 10:56:05

    Free Pascal Compiler version 3.0.0 [2015/11/16] for i386
    Copyright (c) 1993-2015 by Florian Klaempfl and others
    Target OS: Win32 for i386
    Compiling foo.pas
    foo.pas(4,9) Warning: Variable "s1" does not seem to be initialized
    foo.pas(6,8) Warning: Variable "s" does not seem to be initialized
    Linking foo.exe
    11 lines compiled, 0.0 sec, 27520 bytes code, 1268 bytes data
    2 warning(s) issued

    测试数据 #0: Accepted, time = 0 ms, mem = 804 KiB, score = 10

    测试数据 #1: Accepted, time = 687 ms, mem = 800 KiB, score = 10

    测试数据 #2: Accepted, time = 0 ms, mem = 800 KiB, score = 10

    测试数据 #3: Accepted, time = 31 ms, mem = 804 KiB, score = 10

    测试数据 #4: Accepted, time = 703 ms, mem = 800 KiB, score = 10

    测试数据 #5: Accepted, time = 15 ms, mem = 800 KiB, score = 10

    测试数据 #6: Accepted, time = 265 ms, mem = 800 KiB, score = 10

    测试数据 #7: Accepted, time = 406 ms, mem = 800 KiB, score = 10

    测试数据 #8: Accepted, time = 671 ms, mem = 800 KiB, score = 10

    测试数据 #9: Accepted, time = 390 ms, mem = 800 KiB, score = 10

    Accepted, time = 3168 ms, mem = 804 KiB, score = 100

    代码
    var k,s1,s,i:longint;
    begin
    readln(k);
    while s1<1 do
    begin
    s:=s+1;
    if s>20000 then begin write('NO SOLUTION'); exit; end;
    for i:=1 to s do if s mod i=0 then s1:=s1+1;
    if s1<>k then s1:=0
    else write(s);
    end;
    end.

  • 0
    @ 2016-06-07 21:24:40

    打表打法吼啊。
    ```c++
    #include<cstdio>
    using namespace std;

    int ans[]={-1,1,2,4,6,16,12,64,24,36,48,1024,60,4096,192,144,120,-1,180,-1,240,576,3072,-1,360,1296,12288,900,960,-1,720,-1,840,9216,-1,5184,1260,-1,-1,-1,1680,-1,2880,-1,15360,3600,-1,-1,2520,-1,6480,-1,-1,-1,6300,-1,6720,-1,-1,-1,5040,-1,-1,14400,7560,-1,-1,-1,-1,-1,-1,-1,10080,-1,-1,-1,-1,-1,-1,-1,15120,-1,-1,-1,-1,-1,-1,-1,-1,-1};
    int n;

    int main()
    {
    scanf("%d",&n);
    if(ans[n]<0)
    printf("NO SOLUTION\n");
    else
    printf("%d\n",ans[n]);
    return 0;
    }
    ```

  • 0
    @ 2016-01-26 18:24:12

    枚举f(i)
    f(i)中也用j枚举 如果i mod j=0,则有i mod (i/j)=0.计数器能加2.
    但是,如果i是j的平方,那么两个因子是同一个,计数器只能加1.
    没想到升四星的竟是如此水题……还是纪念一下
    ###Pascal Code
    program p1229;
    var
    k,i:longint;

    function f(i:longint):longint;
    var
    j,c:longint; //j循环变量, c计数器
    begin
    c:=0;
    for j:=1 to trunc(sqrt(i)) do
    begin
    if i=sqr(j) then //i是j平方的判断
    begin
    inc(c,1);
    continue; //跳过普通判断
    end;
    if i mod j=0 then inc(c,2); //普通判断
    end;
    f:=c;
    end;

    begin //main
    readln(k);
    for i:=1 to 20000 do //枚举f(i)
    if f(i)=k then
    begin
    writeln(i);
    halt;
    end;
    writeln('NO SOLUTION');
    end.

  • 0
    @ 2015-10-25 20:26:54

    此题枚举即可,时间复杂度20000*(sqrt(1)+sqrt(2)+....+sqrt(20000))
    测试数据 #0: Accepted, time = 1 ms, mem = 524 KiB, score = 10
    测试数据 #1: Accepted, time = 15 ms, mem = 524 KiB, score = 10
    测试数据 #2: Accepted, time = 2 ms, mem = 524 KiB, score = 10
    测试数据 #3: Accepted, time = 2 ms, mem = 520 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 524 KiB, score = 10
    测试数据 #5: Accepted, time = 15 ms, mem = 520 KiB, score = 10
    测试数据 #6: Accepted, time = 15 ms, mem = 524 KiB, score = 10
    测试数据 #7: Accepted, time = 8 ms, mem = 524 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 524 KiB, score = 10
    测试数据 #9: Accepted, time = 15 ms, mem = 524 KiB, score = 10
    Accepted, time = 103 ms, mem = 524 KiB, score = 100
    程序如下:
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <functional>
    using namespace std;
    int main()
    {
    int k;
    int i;
    int j;
    int c;
    int sqr;
    cin >> k;
    for (i = 1; i <= 20000; i++)
    {
    c = 0;
    sqr = (int)sqrt(i);
    for (j = 1; j <= sqr; j++)
    {
    if ((i%j) == 0)
    {
    if (j == sqr)
    {
    if (sqr*sqr == i)
    {
    c++;
    }
    else
    {
    c += 2;
    }
    }
    else
    {
    c += 2;
    }
    }

    }
    if (c == k)
    {
    cout << i << endl;
    return 0;
    }
    }
    cout << "NO SOLUTION" << endl;
    return 0;
    }

  • 0
    @ 2015-10-15 20:12:42

    直接枚举是要超时的。不信你输个80,差不多要等1秒。
    因此可以利用一些数学结论。

    比如16这个数,被2整除了,肯定还能被一个数整除,那就是8.也就是说你从1枚举到根号下那个数,如果能被某个数整除,计数器就+2.
    但是有特例,比如4*4=16,显然我们记了2次,特判一下即可。
    ###pascal code
    program P1229;
    var k,n,ans,i,j:longint;
    s:real;
    begin
    read(k);
    for i:=1 to 20000 do
    begin
    ans:=2;
    for j:=2 to trunc(sqrt(i)) do
    begin
    if i mod j=0 then
    ans:=ans+2;
    end;
    s:=sqrt(i); if s-trunc(s)=0 then dec(ans);
    if ans=k then
    begin
    write(i); exit;
    end;
    end;
    write('NO SOLUTION');
    end.

  • 0
    @ 2015-05-09 19:48:16

    枚举就可以了,注意特判n是完全平方数的情况。

    Pascal Code

    var
    i,k:longint;
    function f(n:longint):longint;
    var
    m,num,i:longint;
    begin
    num:=0;
    m:=round(sqrt(n));
    for i:=1 to m do
    if n mod i=0 then num:=num+2;
    if n=m*m then dec(num); //特判
    exit(num);
    end;
    begin
    readln(k);
    for i:=1 to 20000 do
    if f(i)=k
    then begin
    writeln(i);
    halt;
    end;
    writeln('NO SOLUTION');
    end.

  • 0
    @ 2015-03-07 21:09:24

    var
    i,j,k,n,m,s,t,ans:longint;
    function f(k:longint):longint;
    var i,j:longint;
    begin
    f:=0;
    for i:=1 to trunc(sqrt(k)) do
    if k mod i=0 then
    begin
    inc(f);
    if k div i<>i then inc(f);
    end;
    end;
    begin
    readln(k);
    for i:=1 to 20000 do
    if f(i)=k then
    begin
    writeln(i);
    halt;
    end;
    writeln('NO SOLUTION');
    end.

  • 0
    @ 2015-01-31 17:37:02

    var a,b,c:longint;
    e:array[1..20000]of longint;
    begin
    readln(c);
    for a:=2 to 20000 do
    if e[a]=c-2 then
    begin
    writeln(a);
    halt;
    end
    else
    for b:=2 to 20000 div a do
    inc(e[a*b]);
    writeln('NO SOLUTION');
    end.

  • 0
    @ 2014-03-20 19:57:54

    vijos又一道不用数组的题

    var n,i:longint;
    function pd(x:longint):longint;
    var sum,j:longint;
    begin
    sum:=2;
    for j:=2 to trunc(sqrt(x)) do if x mod j=0 then inc(sum,2);
    if sqr(trunc(sqrt(x)))=x then dec(sum);
    exit(sum);
    end;
    begin
    readln(n);
    for i:=1 to 20000 do if pd(i)=n then begin writeln(i);halt;end;
    writeln('NO SOLUTION');
    end.

  • 0
    @ 2013-11-05 20:42:00

    做这种题无非是想刷通过率。
    第一次交还WA了

  • 0
    @ 2013-11-03 08:19:26

    var
    i,j,n,m,k:longint;
    begin
    readln(k);
    for i:=1 to 50000 do
    begin
    n:=0;
    for j:=1 to trunc(sqrt(i)) do
    if (i mod j=0) then inc(n);
    n:=n*2;
    if j*j=i then n:=n-1;
    if n=k then
    begin
    writeln(i) ;
    halt;
    end;
    end;
    writeln('NO SOLUTION');
    end.

    枚举轻松无压力。。。。

  • 0
    @ 2013-08-03 19:28:04

    测试数据 #0: Accepted, time = 0 ms, mem = 820 KiB, score = 10
    测试数据 #1: Accepted, time = 515 ms, mem = 820 KiB, score = 10
    测试数据 #2: Accepted, time = 7 ms, mem = 824 KiB, score = 10
    测试数据 #3: Accepted, time = 31 ms, mem = 820 KiB, score = 10
    测试数据 #4: Accepted, time = 546 ms, mem = 824 KiB, score = 10
    测试数据 #5: Accepted, time = 15 ms, mem = 824 KiB, score = 10
    测试数据 #6: Accepted, time = 187 ms, mem = 824 KiB, score = 10
    测试数据 #7: Accepted, time = 296 ms, mem = 824 KiB, score = 10
    测试数据 #8: Accepted, time = 500 ms, mem = 828 KiB, score = 10
    测试数据 #9: Accepted, time = 281 ms, mem = 824 KiB, score = 10
    Accepted, time = 2378 ms, mem = 828 KiB, score = 100
    我想自杀……

信息

ID
1229
难度
4
分类
其他 | 数学 点击显示
标签
(无)
递交数
2036
已通过
939
通过率
46%
被复制
4
上传者