ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

HDU-4407-Sum(ÈݳâÔ­Àí)
2015-07-20 17:35:25 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:2´Î
Tags£ºHDU-4407-Sum Èݳâ Ô­Àí
Problem Description XXX is puzzled with the question below:

1, 2, 3, ..., n (1<=n<=400000) are placed in a line. There are m (1<=m<=1000) operations of two kinds.

Operation 1: among the x-th number to the y-th number (inclusive), get the sum of the numbers which are co-prime with p( 1 <=p <= 400000).
Operation 2: change the x-th number to c( 1 <=c <= 400000).

For each operation, XXX will spend a lot of time to treat it. So he wants to ask you to help him.

Input There are several test cases.
The first line in the input is an integer indicating the number of test cases.
For each case, the first line begins with two integers --- the above mentioned n and m.
Each the following m lines contains an operation.
Operation 1 is in this format: "1 x y p".
Operation 2 is in this format: "2 x c".
Output For each operation 1, output a single integer in one line representing the result.

Sample Input
1
3 3
2 2 3
1 1 3 4
1 2 3 6

Sample Output
7
0

Source 2012 ACM/ICPC Asia Regional Jinhua Online
˼·£ºm<=1000 ºÍ ÊýÁгõʼ״̬Ϊ1,2,3,..n ÊǸÃÌâµÄÍ»ÆÆ¿Ú¡£¶ÔÓÚÿһ´ÎѯÎÊ£¬ÏȲ»¿¼ÂÇÊý×Ö±»ÐÞ¸ÄÁË£¬ÄÇÎÒÃÇ¿ÉÒÔÖ±½ÓÓÃÇóºÍ¹«Ê½°Ñxµ½yÖ®¼äµÄÊý×ֵĺÍÇó³öÀ´£¬È»ºóÔÙ¼õÈ¥ÄÇЩ²»ºÍp»¥ÖʵÄÊý(ÓÃÈݳâÔ­Àí)£¬ÔÙ¶ÔÐ޸ĹýµÄÊý½øÐÐÌØÅм´¿É¡£
#include 
  
   

int num,idx[1005],val[1005],prime[10],p[40000];

inline bool check(int x)
{
    int i;

    for(i=0;i
   
    i) p[cnt++]=i; } //------------------------------------------ scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); cnt=0; for(i=1;i<=m;i++) { scanf("%d",&type); if(type==1) { scanf("%d%d%d",&a,&b,&c); ans=(long long)(a+b)*(b-a+1)/2; num=0;//ÖÊÒòÊýµÄ¸öÊý //»ñÈ¡cµÄÖÊÒòÊý----------------- last=0; while(c>1) { if(c%p[last]==0) { prime[num++]=p[last]; c/=p[last]; while(c%p[last]==0) c/=p[last]; } last++; } //------------------------------- //ÈݳâÔ­Àí------------------------- for(j=1;j<(1<
    
     =a && idx[j]<=b) { if(!check(idx[j])) { if(check(val[j])) ans+=val[j]; } else { if(check(val[j])) ans=ans+val[j]-idx[j]; else ans-=idx[j]; } } } //-------------------------------------------------------- printf("%I64d\n",ans); } else { scanf("%d%d",&a,&b); for(j=0;j
      
     
    
   
  
¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºASP.NET¨D015£ºASP.NETÖÐÎÞË¢ÐÂÒ.. ÏÂһƪ£ºhdu 4407 Sum Èݳâ+ÀëÏß

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤ÓÐûÓÐÊʺÏÐÂÊÖÁ·Ï° (2025-12-26 01:48:47)
¡¤ÓÃÇ廪¾µÏñÍøÔõôÏ (2025-12-26 01:48:44)
¡¤Çë±È½ÏPythonºÍRÓïÑÔ (2025-12-26 01:48:42)
¡¤JAVAÏÖÔڵľÍÒµ»·¾³ (2025-12-26 01:19:24)
¡¤×îºÃµÄjava·´±àÒ빤 (2025-12-26 01:19:21)